perl学习

本文介绍了Perl编程语言的基础知识,包括基本语法、变量类型如标量、数组及哈希表的使用方法,并通过示例展示了如何进行简单的文件输入输出操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/usr/bin/perl

#In order to make the code more robust ,to start every program with the following lines

use strict;

use warnings;

#basic syntax over

print "Hello , world/n";

print 'hello , world/n';

print 73;

print("/nhello , world/n");

#perl variable types

#Scalars

my $name = "renbing";

my $age = 22;

print "my name is $name,my age is $age./n";

#arrays

my @animals = ("camel", "llama", "owl");

my @numbers = (23,22,66);

my @mixed = ("camel", 43, 1.332);

print $animals[0];

#the special variable $#array tells you the index of the last element of an array;

#$#array +1 to tell you how many items there are in an array

print $mixed[$#mixed];

print "/n";

print @numbers[1,2];

print "/n";

print @numbers[0..$#numbers];

#hashes

#my %fruit_color = ("apple", "red", "banana", "yellow");

my %fruit_color = (

apple => "red",

banana => "yellow",

);

print "/n";

print $fruit_color{"apple"};

my @fruits = keys %fruit_color;

my @colors = values %fruit_color;

print "/n";

#key string comparison 

# eq ne lt gt le ge

#file and i/o

open(my $in, "<", "input.txt") or die "can't open"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值