perl学习

1.#!/usr/bin/perl
@lines = `perldoc -u -fatan2`;
foreach (@lines) {
      s/\w<([^>]+)>/\U$1/g;
      print;
}

2.#!/usr/bin/perl
$bj =  <STDIN> ;
$y_zc= 2 * 3.141592654 * ${bj};
if($bj le 0 ){
   print "Result is 0.\n";
   }else{
   print "Result is $y_zc.\n";
}

3.#!/usr/bin/perl
$num_1=<STDIN>;
$num_2=<STDIN>;
$res=$num_1 * $num_2;
print "Result is $res.\n"

4.#!/usr/bin/perl
#Please enter the number:
$cha=<STDIN>;
#Please enter the number:
$num=<STDIN>;
$res=$cha x $num;
print "Result is $res.\n"

5.#!/usr/bin/perl
@rocks = qw/ bedrock slate lava /;
foreach $rock (@rocks) {
    $rock = "\t$rock";
    $rock .= "\n";
}
print "The rocks are:\n", @rocks;
   

 6.#!/usr/bin/perl
foreach (1..10){
       print "I can count to $_!\n";
}

7.#!/usr/bin/perl
@ch = <STDIN>;
@pr = sort @ch;
print "The stdin by your enter is @pr.\n"

 8.#!/usr/bin/perl
@nu = <STDIN>;
@na = qw/ fred betty barney dino wilma pebbles bamm-bamm /;
print "Your enter is @na[@nu].\n"

9.#!/usr/bin/perl
chomp(@ech = <STDIN>);
@ech = sort @ech;
print "Your enter is @ech.\n"

posted on 2013-07-07 22:58  awk  阅读(241)  评论(0)    收藏  举报

导航