in reply to Re: Re: What Is Going On Here ?????
in thread What Is Going On Here ?????

As repson says $_ is a global, to preserve your initial array I guess you'd have to protect it with
while (local $_ = <IN>) {
in the do_something sub

And now, as he looked and saw the whole Hellespont covered with the vessels of his fleet, and all the shore and every plain about Abydos as full as possible of men, Xerxes congratulated himself on his good fortune; but after a little while he wept...
Asked why he was weeping he replied
..."There came upon me," replied he, "a sudden pity, when I thought of the shortness of man's life, and considered that of all this host, so numerous as it is, not one will be alive when a hundred years are gone by."
The History of Herodotus By Herodotus Written about 440 B.C.

Replies are listed 'Best First'.
Re: Re: Re: Re: What Is Going On Here ?????
by Fastolfe (Vicar) on Nov 21, 2000 at 19:17 UTC
    I think it's a lot more readable to simply say:
    local $_;
    at the top of do_something. No sense in making Perl do localization work for every iteration of the loop.

    Generally (and this is for everyone else), if you use any functions that make use of $_ in this fashion, you should remember to mask its global value while you use it (via local), so that when your function returns, anything that depends on the value of $_ elsewhere won't be disappointed.