in reply to Re: WWW::Mechanize and following multiple links
in thread WWW::Mechanize and following multiple links

petdance,
I tend to pay close attention to people who have had a fair amount of experience. When I first read what you wrote, I got a little nervous because I often use foreach loops without specifying a looping variable. I thought about it a bit, and just about everything in perl that sets $_ localizes it first like map, grep, foreach loops, etc (while loops excluded). I didn't do an exhaustive search (checked the CB) but the list was quite short of things that I found that modify $_: Since $_ is aliased, I am intentionally changing $_ if I use one of those. Am I completely missing the boat here? I am not saying there isn't any case where this can't bite you but is it more common than I think or are you just protecting against Murphy's Law?

Cheers - L~R

  • Comment on Re^2: WWW::Mechanize and following multiple links

Replies are listed 'Best First'.
Re^3: WWW::Mechanize and following multiple links
by ysth (Canon) on Nov 25, 2004 at 02:08 UTC
    Those while loops that you are excluding are the primary danger here; the problem scenario usually manifests something like:
    sub foo { while (<$fh>) { ... } } for (@important) { ... foo(); ... }
    and presto, elements in @important are replaced by lines from $fh.