Perl 源程序 use strict; use warnings;
my $what = 'fred|barney'; while ( 9.2 Perl 源程序 use strict; use warnings; my $in = $ARGV[0]; unless (defined $in) { die \"Usage: $0 filename\"; } my $out = $in; $out =~ s/(\\.\\w+)?$/.out/; unless (open IN, \"<$in\") { die \"Can't open '$in': $!\"; } unless (open OUT, \">$out\") { die \"Can'twrite '$out': $!\"; } while ( 9.3 Perl 源程序 use strict; use warnings; my $in = $ARGV[0]; unless (defined $in) { die \"Usage: $0 filename\"; } my $out = $in; $out =~ s/(\\.\\w+)?$/.out/; unless (open IN, \"<$in\") { die \"Can't open '$in': $!\"; } unless (open OUT, \">$out\") { die \"Can'twrite '$out': $!\"; } while ( } 运行结果 9.4 Perl 源程序 use strict; use warnings; $^I = \".bak\"; while (<>) { if (/^use warnings;/) { $_.= \"## Copyright (C) 20XX by Yours Truly\\n\"; } print; } 运行结果 9.5 Perl 源程序 use strict; use warnings; my %do_these; foreach (@ARGV) { $do_these{$_} = 1; } while (<>) { if (/^## Copyright/) { delete $do_these{$ARGV}; } } @ARGV = sort keys %do_these; $^I = \".bak\"; while (<>) { if (/^use warnings;/) { $_ .= \"## Copyright (C) 20XX by Yours Truly\\n\"; } print; } 运行结果 10.1 Perl 源程序 use strict; use warnings; my $secret = int(1 + rand 100); #print \"Don't tell anyone, but the secret number is $secret.\\n\"; while (1) { print \"Please enter a guess from 1 to 100: \"; chomp(my $guess = 运行结果 10.2 Perl 源程序 use strict; use warnings; use 5.010; my $Debug = $ENV{DEBUG} // 1; my $secret = int(1 + rand 100); print \"Don't tell anyone, but the secret number is $secret.\\n\" if $Debug; while (1) { print \"Please enter a guess from 1 to 100: \"; chomp(my $guess = 运行结果 10.3 Perl 源程序 use strict; use warnings; use 5.010; $ENV{ZERO} = 0; $ENV{EMPTY} = ''; $ENV{UNDEFINED} = undef; my $longest = 0; foreach my $key (keys %ENV) { my $key_length = length($key); $longest = $key_length if $key_length>$longest; } foreach my $key (sort keys %ENV ) { printf \"%-${longest}s %s\\n\} 运行结果 因篇幅问题不能全部显示,请点此查看更多更全内容