you are not reading the files properly.
use 2 "while loops". the outer for traversing the
command line args while the inner for reading and
checking the file contents. use "break" in the inner
"while loop" when you get a blank line to go to the
outer "while loop".

cheers 

 --- Harry Putnam <[EMAIL PROTECTED]> wrote: > I know
its possible to force perl to read the next
> file but have
> forgotten how to do it.
> 
> The simple script below is supposed to read message
> files that are on
> disk one message per file.
> 
> I want to go to the next file when the first blank
> line is seen.
> I don't see how $cnt can equal one more than once
> per file in the
> script below yet I get output that indicates it
> does.
> Maybe its `last' I'm looking for but trying that in
> place of next and
> I get one hit and the script stops.
> 
> Judging by the output below its resetting to 0 on
> every blank line,
> not going to the next file.
> Maybe I've been staring at this too long...
> 
> cat test.pl
>   #!/usr/local/bin/perl -w
>  
>   $regex = shift;
>   while(<>){
>      $cnt++;
>      if($cnt == 1){
>        print "$ARGV\n";
>      }
>      if(/$regex/){
>        printf "%-3d %s", $cnt, $_;
>      }elsif(/^$/){
>        $cnt = 0;
>        next;
>      }
> }
> 
> Run it against a directory full of 4 messages:
> 
> ../test.pl '^Date: ' ~/Mail/test/[0-9]*
> 
> /home/reader/Mail/test/1
> 40  Date: Wed, 11 Sep 2002 17:05:03 -0700
> /home/reader/Mail/test/1
> /home/reader/Mail/test/1
> /home/reader/Mail/test/1
> /home/reader/Mail/test/1
> /home/reader/Mail/test/1
> /home/reader/Mail/test/2
> 63  Date: 12 Sep 2002 01:08:31 +0100
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/2
> /home/reader/Mail/test/3
> 60  Date: Wed, 11 Sep 2002 20:24:12 -0400
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/3
> /home/reader/Mail/test/4
> 20  Date: Thu, 12 Sep 2002 01:51:34 +0100
> /home/reader/Mail/test/4
> /home/reader/Mail/test/4
> /home/reader/Mail/test/4
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>  

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to