Larsen, Errin M HMMA/IT wrote:
Hi Perl-Crunchers,

Hello,

  I've got the following code:

#!/usr/bin/perl

use warnings;
use strict;

my $logdir = '/some/application/logs';
my @logs = <$logdir/*>;

push @ARGV, @logs;
while( <> ) {
        print "$filename:\n$_" if( /with errors/ );
}

Of course, my problem is that I'm not filling in $filename in that print
statement with a value.  I'd really like to be able to put the name of
the file the diamond ('<>') operator is currently parsing in there.  Is
that possible?  Do I have access to the individual filenames AS they are
being used in the while statement?

The "magical" diamond operator uses ARGV as the current filehandle and stores the name of the current file in the scalar $ARGV so:


while( <> ) {
        print "$ARGV:\n$_" if /with errors/;
}




John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to