perl的学习 1

来源:互联网 发布:缩小手机屏幕显示软件 编辑:程序博客网 时间:2024/04/28 23:26

1. With Perl, command-line arguments are stored in the array named @ARGV.
#!/usr/bin/perl
#---------------------#
#  PROGRAM:  argv.pl  #
#---------------------#

$numArgs = $#ARGV + 1;
print "thanks, you gave me $numArgs command-line arguments:/n";

foreach $argnum (0 .. $#ARGV) {

   print "$ARGV[$argnum]/n";

}
result :
[root@localhost perl]# ./argv.pl 2 2 2 fd
thanks, you gave me 4 command-line arguments:
2
2
2
fd


2. Scalar variables
$priority = 9;
$priority = 'high';
$priority = '9';
$default = '0009';

[root@localhost perl]# cat basic.pl
#!/usr/bin/perl
#---------------------#
#  PROGRAM:  basic.pl  #
#---------------------#

$a = 'fff';
$b = 'x';
$c = 3;
print '$a and $b';
print "/n";
print "$a and $b";
print "/n";
print $a . $c;
print "/n";
print $a x $c;
print "/n";

result :
[root@localhost perl]# perl basic.pl
$a and $b
fff and x
fff3
fffffffff

3. reg
http://www.comp.leeds.ac.uk/Perl/matching.html

4. subroutine
http://www.comp.leeds.ac.uk/Perl/subroutines.html

原创粉丝点击