Perl中一种有趣输入的方法,钻石操作符<>
例子:
它会把fred文件中的内容,当做输入流,进行处理,默认会在$_进行读取
例子:
点击(此处)折叠或打开
-
[root@zsd script]# cat
ex1_2.pl
-
#!/usr/bin/perl
-
while(<>){
-
chomp;
-
print "It was $_ that I saw!\n";
-
}
-
[root@zsd script]# cat
fred
-
hello everyone
-
i see
-
sky is great player
-
[root@zsd script]# ./ex1_2.pl
fred
-
It was hello everyone that I
-
It was i see that I
-
It was sky is great player that I
- [root@zsd script]#