Re: Diamond Operator and Filenames

2005-02-18 Thread John W. Krahn
John W. Krahn wrote:
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
Larsen, Errin M HMMA/IT wrote:
Hi Perl-Crunchers,
 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?
I believe that $ARGV[0] has the file being processed.
No, the array @ARGV doesn't change inside the while loop.
Sorry, see my other post which shows that @ARGV does indeed change.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Diamond Operator and Filenames

2005-02-18 Thread John W. Krahn
Larsen, Errin M HMMA/IT wrote:
  So, the <> operator shift()s the filenames off the top of @ARGV?
That's usefull knowledge.
Yes, but it does it before the loop starts!
$ perl -le' 

print for @ARGV; 

print; 

while (<>) { print "$ARGV\t$ARGV[0]" if $. == 1; close ARGV if eof } 

print;
print for @ARGV;
' test04.txt test05.txt test06.txt
test04.txt
test05.txt
test06.txt
test04.txt  test05.txt
test05.txt  test06.txt
test06.txt
You can see that the current file name has already been removed from @ARGV
inside the while loop.

  On a side note, out of curiosity, can I manipulate the @ARGV array
inside the while loop?  Or will that cause "unexpected behaviour"?
Yes you can if you *REALLY* want to do that.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Diamond Operator and Filenames

2005-02-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
John W. Krahn wrote:
> Wagner, David --- Senior Programmer Analyst --- WGO wrote:
>> Larsen, Errin M HMMA/IT wrote:
>> 
>>> Hi Perl-Crunchers,
>>> 
>>>  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?
>> 
>> 
>> I believe that $ARGV[0] has the file being processed.
> 
> No, the array @ARGV doesn't change inside the while loop.
> 
> 
> John
> --
> use Perl;
> program
> fulfillment

Corrct, though the variable $ARGV holds the current file being 
processed in <>,  So you can see by doing something like:

use strict;
use warnings;

printf "Scalar of ARGV: %d\n", scalar(@ARGV);

my $MyCurrFile = '';

while ( <> ) {
if ( $ARGV ne  $MyCurrFile ) {
print "Filename: " . $ARGV . "\n";
$MyCurrFile = $ARGV
 }
 }

Tested and I had 13 files and 13 printed out.

I apolgize for the mistake on @ARGV, though if not used in regards to 
the <>, you can shift, pop, etc like anyother array element.

Wags


***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




Re: Diamond Operator and Filenames

2005-02-18 Thread John W. Krahn
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
Larsen, Errin M HMMA/IT wrote:
Hi Perl-Crunchers,
 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?

I believe that $ARGV[0] has the file being processed.
No, the array @ARGV doesn't change inside the while loop.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Diamond Operator and Filenames

2005-02-18 Thread John W. Krahn
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]
 



RE: Diamond Operator and Filenames

2005-02-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Larsen, Errin M HMMA/IT wrote:
>> Larsen, Errin M HMMA/IT wrote:
>>> Hi Perl-Crunchers,
>>> 
>>>   I've got the following code:
>>> 
> 
>   <>
> 
>>> 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?
>>> 
>>> Thanks ahead of time,
>>> 
>>> --Errin
>> 
>>  I believe that $ARGV[0] has the file being processed.
>> So I think you could do something like:
>> 
>>  if ( $. == 1 ) {  # on the first read of the current file
>> print "Filename: " . $ARGV[0] . "\n";
>>}
>> 
>> Wags ;)
> 
> 
> Hi again,
> 
>   So, the <> operator shift()s the filenames off the top of @ARGV?
> That's usefull knowledge.
> 
>   On a side note, out of curiosity, can I manipulate the @ARGV array
> inside the while loop?  Or will that cause "unexpected behaviour"?
> 
> --Errin
As they say, ALL things are possbile ( in Perl ), but one would want to 
be careful, though you can change, delete and splice @ARGV like any other array.

Wags ;)


***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




RE: Diamond Operator and Filenames

2005-02-18 Thread Larsen, Errin M HMMA/IT
> Larsen, Errin M HMMA/IT wrote:
> > Hi Perl-Crunchers,
> > 
> >   I've got the following code:
> > 

  <>

> > 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?
> > 
> > Thanks ahead of time,
> > 
> > --Errin
> 
>   I believe that $ARGV[0] has the file being processed. 
> So I think you could do something like:
> 
>   if ( $. == 1 ) {  # on the first read of the current file
>  print "Filename: " . $ARGV[0] . "\n";
>}
> 
> Wags ;)


Hi again,

  So, the <> operator shift()s the filenames off the top of @ARGV?
That's usefull knowledge.

  On a side note, out of curiosity, can I manipulate the @ARGV array
inside the while loop?  Or will that cause "unexpected behaviour"?

--Errin 

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




RE: Diamond Operator and Filenames

2005-02-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Larsen, Errin M HMMA/IT wrote:
> Hi Perl-Crunchers,
> 
>   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?
> 
> Thanks ahead of time,
> 
> --Errin

I believe that $ARGV[0] has the file being processed. So I think you 
could do something like:

if ( $. == 1 ) {  # on the first read of the current file
   print "Filename: " . $ARGV[0] . "\n";
   }

Wags ;)


***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


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




Diamond Operator and Filenames

2005-02-18 Thread Larsen, Errin M HMMA/IT
Hi Perl-Crunchers,

  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?

Thanks ahead of time,

--Errin

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