![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Very curious Problem...by muba (Priest) |
on Jan 23, 2013 at 12:06 UTC ( #1014892=note: print w/replies, xml ) | Need Help?? |
++ for demonstrating the problem in a simple self-contained piece of code. One advantage of reducing a problem to the smallest set of instructions that replicates the problem, is that it allows you to debug it using your Eyeball Mk I (and maybe a pencil and a piece of paper). Using your sample code, let's Eyeball Debug it, starting at the top and following along with the flow of the code. I don't know how you pronounce $_ — maybe you call it "dollar underscore" whatever, but I call it "it". That's right. So if ($_ == 3), to me, reads "if it equals 3", and @foo = grep { defined $_ } @bar; I would pronounce as "at-foo now is ... grep-if it is-defined ... from at-bar". Why do I share this? Because I feel it really helps to think of $_ as being "it". Let's go:
This clearly shows where, how, and why it (or dollar-underscore) got changed. Solutions have been given elsewhere in this thread. I just wanted to show you how I would've debugged it. The code, that is, not the value of $_. Or maybe both.
In Section
Seekers of Perl Wisdom
|
|