寒假【perl语言学习脚本】7.1 7.2 7.3 7.4 7.5 7.6 7.7

寒假【perl语言学习脚本】7.1 7.2 7.3 7.4 7.5 7.6 7.7
#!/usr/bin/perl -w
while(<>){#钻石操作符,不加参数,输入读取到默认的$
if (/fred/){
print;
}
}
#another way
while(){
if (/fred/){
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } #从文件中读入文本来测…!";
#打开文本#如果open失败,die会终止程序的运行,告诉我们无法打开文件#第五章p108冒号后面的!!代表可读的系统错误信息,!会给我们一个解释
while(defined($
=)){#逐行读取文本
if (/fred/){
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } close FILE;…!";
#打开文本#如果open失败,die会终止程序的运行,告诉我们无法打开文件#第五章p108冒号后面的!!代表可读的系统错误信息,!会给我们一个解释
while(defined($=)){#逐行读取文本
if (/(f|F)red/){
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } close FILE;…!";
#打开文本#如果open失败,die会终止程序的运行,告诉我们无法打开文件#第五章p108冒号后面的!!代表可读的系统错误信息,!会给我们一个解释
while(defined($
=)){#逐行读取文本
if (/./){
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } close FILE;…!";
while(defined($=)){#逐行读取文本
if (/1[a-z]+/){# +用于使前面的字符与后面的字符至少匹配一次,也可以任意次地进行匹配
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } close FILE;…!";
while(defined($
=)){#逐行读取文本
if (/(\S)\1/){#\S字符集会匹配所有的非空白符,而圆括号可以使用反向引用\1来匹配紧跟着它的同样的字符
print KaTeX parse error: Expected 'EOF', got '}' at position 6: _; }̲ } close FILE;…!";
while(defined($=)){#逐行读取文本
if (/wilma.*fred|fred.*wilma/){
print $
;
}
}
close FILE;


  1. A-Z ↩︎