#!/usr/bin/perl -w
Copyright © 2019 by Yours Truly
Copyright © 2019 by Yours Truly
my $what = ‘fred’; ="barneyfredfredfredbarney";/(what){2}/;
print “$&\n”;
#!/usr/bin/perl -w
Copyright © 2019 by Yours Truly
my $what = ‘fred|barney’; ="fredfredbarneyqeq";/(what){3}/;
print “$&\n”;
#!/usr/bin/perl -w
my $what = ‘fred|barney’; ="barneyfredfredqsss";/(what){3}/;
print “$&\n”;
#!/usr/bin/perl -w
my $whatt = ‘fred|barney’; ="barneybarneybarneyqsss";/(whatt){3}/;
print “$&\n”;
#!/usr/bin/perl -w
Copyright © 2019 by Yours Truly
$filename = $ARGV[0];#读取 KaTeX parse error: Expected 'EOF', got '\/' at position 16: filename =~ s/(\̲/̲\w+)?/.out/;#绑定操作符 也可以s#.(\S)*#.out#
print “KaTeX parse error: Expected 'EOF', got '\n' at position 9: filename\̲n̲";
open ONE, ">filename”; #打开文件
while (<>) {
s/fred/Larry/gi;
print ONE $_;#如果把这个打开的文件ONE去掉,test.out里是空的,都输出在了屏幕上
}
close ONE;
#当perl脚本运行时,从命令行上传递给它的参数存储在内建数组@ARGV中,
#@ARGV是PERL默认用来接收参数的数组可以有多个参数,ARGV[0]是表示接收到的第一个参数,ARGV[1]表示第二个
\S 匹配非空白字符
$#作为一个变量表示打印数字时默认的数字输出格式,后面加上ARGV
#$#ARGV为命令行参数(不包括命令本身)的个数减一,即数组@ARGV最后一个元素的索引。
#用处也就是在程序开始时判断命令行参数个数,或者直接操作最后一个命令行参数。
#!/usr/bin/perl -w
Copyright © 2019 by Yours Truly
$filename = $ARGV[0];#读取 KaTeX parse error: Expected 'EOF', got '#' at position 14: filename =~ s#̲\.(\S)*#\.2out#…filename\n";
open ONE, “>$filename”; #打开文件
while (<>) {
s/fred/ /gi;
s/wilma/Fred/gi;
s/ /Wilma/gi;
print ONE $_;#如果把这个打开的文件ONE去掉,test.out里是空的,都输出在了屏幕上
}
#!/usr/bin/perl -w
$^I=".bak";#制作备份
while (<>) {
if (/^#!/) { #是#!开头的那行吗?
$_.="## Copyright © 2019 by Yours Truly\n";
}
print;
}
a.=b 就相当于 把a 和b字符串的内容和并,存入a
=就是简单的赋值
#!/usr/bin/perl -w
my %hash;
foreach (@ARGV) { KaTeX parse error: Expected '}', got 'EOF' at end of input: hash{}=1;
}
#建立哈希,它的键是文件名称
while (<>) {
if (/\A## Copyright/) {
delete KaTeX parse error: Expected '}', got 'EOF' at end of input: hash{ARGV};
}
}
#移除已经包含版权声明行的文件
@ARGV= sort keys %hash;
$^I = “.bak”; #准备备份
while (<>) {
if (/\A#!/) { #是#!开头的那行吗?
$.="## Copyright © 2019 by Yours Truly\n";
}
print;
}
|
请发表评论