To my understanding, "$_" is the default input of the current running 
script/program, hence, if you overwrite $_ in an inner loop, it will overwrite 
$_ for the whole process.  If you do not want to overwrite it, you'll need to 
assign $_ to a scalar before entering the loop that will overwrite $_.

Does that help or am I way off base?

Johnny Roche
Associate, Help Desk
Harvard Management Company
Tel: 617-720-6827
Fax: 617-878-6827
Email: roc...@hmc.harvard.edu

-----Original Message-----
From: Odin Liu [mailto:odinushu...@gmail.com]
Sent: Friday, December 03, 2010 11:26 AM
To: Shawn H Corey; beginners@perl.org
Subject: Re: A strange problem with array outside I/O

Interesting. So if I need deal with an array of files, and I have to use the
array after reading each file. I have to save another copy of the array?

Anyway, thanks for helping.

On Sat, Dec 4, 2010 at 12:16 AM, Shawn H Corey <shawnhco...@gmail.com>wrote:

> 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.
>



--
*Odin Liu
*
RD Engineer
work mail: liuyid...@baidu.com
blog: http://blog.odichy.org/
profile: https://www.google.com/profiles/odinushuaia

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