1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 $_ = 'oireqo````'; 7 8 unless($_ =~ /^a/m){print "no match to a\n"} 9 10 #no match to a 11 12 if(!($_ =~ /^a/m)){print "no match to a\n"} 13 14 #no match to a 15 16 unless($_ =~ /^o/m){print "no match to a"}else{print "match!\n"} 17 18 my $number = 1; 19 20 while($number<12) 21 { 22 $number++;print "$number\n"; 23 } 24 25 #2 26 #3 27 #4 28 #5 29 #6 30 #7 31 #8 32 #9 33 #10 34 #11 35 #12 36 37 until($number<2) 38 { 39 $number--;print "$number\n" 40 } 41 42 #11 43 #10 44 #9 45 #8 46 #7 47 #6 48 #5 49 #4 50 #3 51 #2 52 #1 53 54 print "match!\n"if($_ =~ /^o/m); 55 56 #match! 57 58 my @arr=(1,2,3,4,5,6,7);print foreach(@arr);print"\n"; 59 60 #1234567 61 62 #my @arr_1=(1,2,3,4,5,6,7);print"$k" foreach my $k($#arr_1);print"\n"; 63 #Global symbol "$k" requires explicit package name (did you forget to declare "my $k"?) at t.pl line 62. 64 #syntax error at t.pl line 62, near "$k(" 65 #Execution of t.pl aborted due to compilation errors. 66 67 { 68 my $k = "good"; 69 } 70 #print "$k\n"; 71 72 #Global symbol "$k" requires explicit package name (did you forget to declare "my $k"?) at t.pl line 70. 73 #Execution of t.pl aborted due to compilation errors. 74 75 my @fruit = ('apple','banana','peach','apple','apple');my %match;$match{$_}++ foreach(@fruit);print "$match{$_}\n"foreach(keys %match); 76 77 #1 78 #1 79 #3 80 81 my $five_1= 5;my $six_1 = $five_1++;print "$six_1\t$five_1\n"; 82 my $five_2= 5;my $six_2 = ++$five_2;print "$six_2\t$five_2\n"; 83 84 #5 6 85 #6 6 86 87 my %seen;foreach(@fruit) {print "i 've get $_!\n" if $seen{$_}++;} 88 89 #i 've get apple! 90 #i 've get apple! 91 92 for($_ = "abcdefg";s/(.)//;){print "$1\n";if($1 eq "f"){last;}} 93 94 #a 95 #b 96 #c 97 #d 98 #e 99 #f 100 my %seen; 101 102 READ:while(<>) 103 { 104 foreach(split) 105 { 106 next READ if /\W/;$seen{$_}++; 107 } 108 } 109 110 foreach (keys %seen){print "last:$_ is $seen{$_}\n";last if /dewm/;} 111 foreach (keys %seen){print "next:$_ is $seen{$_}\n";next if /dewm/;} 112 #foreach (keys %seen){print "redo:$_ is $seen{$_}\n";redo if /dewm/;} 113 114 # cat 1.txt 115 # shsjsk 123 116 # dewm 117 # shsjsk 123 118 # shsjsk 123 119 # shsjsk 123 120 # cat 1.txt |perl t.pl 121 #last:shsjsk is 4 122 #next:shsjsk is 4 123 #next:123 is 4 124 #next:dewm is 1 125 #redo:dewm is 1 126 #…… 127 128 my $zero = 0;my $one = 1; 129 if (($zero != 0)&&($one%$zero==2)){print "get!\n"} 130 131 # 132 133 my %zoo;$zoo{'fish'}='cat',$zoo{'mouse'} ='dog';$zoo{'dog'}=""; 134 my $animal=$zoo{'dog'}||'nobody';print "$animal\n"; 135 my $animal_1=$zoo{'panda'}||'nobody';print "$animal_1\n"; 136 my $animal_2=defined $zoo{'dog'}? '1':'nobody';print "$animal_2\n"; 137 my $animal_3=$zoo{'dog'}//'nobody';print "$animal_3\n"; 138 139 #nobody 140 #nobody 141 #1 142 # 143 144 printf "%s\n",$animal_3//'nobody'; 145 146 # 147 148 my $m =12;($m>20)||print "$m\n"; 149 150 #12 151 152 $m>20 or die "wrong judgement"; 153 154 #wrong judgement at t.pl line 152, <> line 5.