perl语言学习之基本操作

1)内置警告

#!/usr/bin/perl-w

2)变量内插

$fred = "majinxin" . "UVM"
$chars = "$fred is right"
print $fred #不需要加双引号

3)if控制结构

$line = <STDIN>;
if($line eq "\n"){
    print "That was just a blank line \n";      
}else{
    print "That line of input was: $line";
}

4)while控制结构。

$count = 0;
while ($count < 10) {
    $count += 2;
    print "count is now $count\n"; #一次打印2 4 6 8 10    
}

5)undef的问题

$madonna = <STDIN>;
if ( defined($madonna)){
    print "The input was $madonna";
}else{
    print "No input available!\n";
}
#defined判断是否是undef值

6)chomp消除末尾\n

$test = <STDIN>;
chomp($test);

 

posted on 2019-03-27 14:33  阿基米德之音  阅读(318)  评论(0编辑  收藏  举报

导航