while  ( <> )  就是直接从  @ARGV 里面读东西

即直接打开命令行参数的文件打开,一行一行读,

相当于

foreach my  $var ( @ARGV )  {
    open my  $F1, '<',  $var  ; # some file name ;
    while ( <$F1> )  {  # line by line
           .....
     }
      close $F1 ;   # close , open another file
}

比如  你这个脚本叫  test.pl

shell>test.pl  1 2 3

就会依次打开文件1,2,3 做处理

这个题目的意思是 打开某个文件,找匹配

如 test.pl  file1
应该会输出包含 /pattern/的行 ,




2009/12/11 天翼 张 <[email protected]>

> 能不能跟我说详细点呀?我还是没有搞懂怎么做。我才学的,可能我太笨了点。
>
> On 12月10日, 下午9时47分, truncatei <[email protected]> wrote:
> > 先写个文件
> > echo "some text" > data.txt
> > 然后运行
> > yourpl.pl data.txt
> >
> > <> 是迭代默认的文件句柄的
> >
> > 或者
> >
> > while (<STDIN>) {
> > ...
> >
> > 2009/12/10 天翼 张 <[email protected]>
> >
> > > 各位高手,我是一个刚学习perl的新手,学到正则表达式的模式测试程序这一节时书中列出了一个用来某些字符串的模式匹配的程序。可是我不知道怎样使
> > > 用,不知到是在命令提示符窗口中输入来测试还是另外调用一个程序来测试我用了两种方法都不行。望各位高手们指点一二。下面是这个程序。
> > > #!/usr/bin/perl
> > > while(<>){
> > >    chiomp;
> > >    if(/YOUR_PATTERN_GOES_HERE/){
> > >      print"Matched:|$`<$&>$'|\n";
> > >     }else{
> > >      print "\uno match:|$_|\n";
> > >     }
> > > }
> >
> > --
> > 如果觉得无聊,您不妨访问Google Reader消遣http://www.google.com/reader/view
> > 要尝试黑版本Google,请访问http://tinyurl.com/yk3yp7j
>
> --
>
> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至 
> [email protected]<perlchina%[email protected]>
> 。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>
>
>


-- 
           Yours Sincerely
                   Zeng Hong

--

您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。


回复