On Mon, Jul 15, 2002 at 11:23:52PM +0800, Connie Chan wrote:
> my @Files = ( ..... ); # List of file names here.
> my @record = ( );
> my $pattern = "whatever";
>
> foreach $file(@Files)
> { open FH, $file;
> while (<FH>)
> { push @record, $file if ($_ =~ /$pattern/ig) }
> close (FH)
> }
>
> ######
>
> @record will probrably grabbed all the file names while
> contained "whatever" .
If the file contains "whatever" more than once, wouldn't this push $file
onto @record once each time "whatever" is seen in the file? You'll probably
want to add a "last" in there:
my @Files = ( ..... ); # List of file names here.
my @record = ( );
my $pattern = "whatever";
foreach $file (@files) {
open(FH, $file);
while (<FH>) {
if (/$pattern/) {
push(@record, $file);
last;
}
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]