小骆驼图书第九章练习;
1.
my $what = "jason";
my $lines = "jason want to go home!";
if($lines =~ /($what){3}/){
print "match the $what \n";
}
else {
print "not match the $what \n";
}
my $in = $ARGV[0]; #从命令行获取参数
if(! define $in){
die "Usage: $0 filename "; #$0 当前运行脚本名
}
my $out = $in;
$out =~ s/(\.\w+)?$/.out/; 替换.后内容
if(!open $in_fh,'<',$in){
die "can't open $in: $!"; #$! 错误信息
}
if(!open,$out_fh,'>',$out){
die "can't open $out: $!";
}
while(<$in_fh>) {
s/aa/AA/gi; #隐式写法
print $out_fh $_; #注意中间没有**,**号
}
my $in = $ARGV[0]; #从命令行获取参数
if(! define $in){
die "Usage: $0 filename "; #$0 当前运行脚本名
}
my $out = $in;
$out =~ s/(\.\w+)?$/.out/; 替换.后内容
if(!open $in_fh,'<',$in){
die "can't open $in: $!"; #$! 错误信息
}
if(!open,$out_fh,'>',$out){
die "can't open $out: $!";
}
while(<$in_fh>) {
chomp;
s/aa/\n/gi; #隐式写法
s/bb/aa/gi;
s/\n/bb/gi; #先将aa替换成\n;待bb替换完成后再将\n替换成bb;
print $out_fh $_; #注意中间没有**,**号
}