Would this satisfy your desired output?

my @ins = @ARGV;
foreach(@ins) {
       open IN, $_;
       my $fn = $_;
       while(<IN>) {
               chomp;
               print "$fn\n";
       }
       close IN;
}

Johnny Roche
Associate, Help Desk
Harvard Management Company
Tel: 617-720-6827
Fax: 617-878-6827
Email: roc...@hmc.harvard.edu
-----Original Message-----
From: Shawn H Corey [mailto:shawnhco...@gmail.com]
Sent: Friday, December 03, 2010 11:16 AM
To: Odin Liu; beginners@perl.org
Subject: Re: A strange problem with array outside I/O

On 10-12-03 11:12 AM, Odin Liu wrote:
> Still confusing. We know that inner loop's $_ overwrite the outer loop's
> $_ only in the inner loop. When the inner loop was over, the $_ would be
> it was in outer loop before the inner loop begin. Outer $_ would be
> restored by Perl automatically.
>
> But why this behavior changes when the inner loop is a diamond
> operation? If it is a Perl syntax, then how can I open a list of file,
> read their content, and then keep the file name list as it was?

No, the behaviour is different because the inner loop is a while one.  A
local copy of $_ would be made if the inner loop was another foreach one.


--
Just my 0.00000002 million dollars worth,
   Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/



The information contained in this e-mail may be confidential and is intended 
solely for the use of the named addressee.
Access, copying or re-use of the e-mail or any information contained therein by 
any other person is not authorized.
If you are not the intended recipient please notify us immediately by returning 
the e-mail to the originator.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to