Your skill will accomplish what the force of many cannot |
|
PerlMonks |
'use strict', debugger, Data::Dumperby TomDLux (Vicar) |
on May 24, 2004 at 14:43 UTC ( [id://355932]=note: print w/replies, xml ) | Need Help?? |
WhenI looked at your code, I wondered that you didn't have parentheses when you call mysub1, but it slipped past me all the same, until I did what you should have done, run the code in the debugger. &mysub2(mysub1) invokes mysub2 with the text 'mysub1'; so @array is not empy. If you used
as you should, you would have been provided the warning
Even without that warning, if you're confused that mysub2() is following the wrong path, the obvious thing to do is to find out what @array DOES contain, since it doesn't contain what you expect it to. You could print out what @_ contains at the routine entrty point, in which situation Data::Dumper is your friend.
will let you see things are not as you thought. Or you could use your debugger. I prefer debugging from emacs (M-x perldb) but not everyone wants to spend the time to learn to use emacs. So use perl -d myscript, then type a letter 's' to 'single-step' into the mysub1() routine. "WOW! What are we doing in mysub2()?". Seeing the code elsewhere than you expected does a lot to guide your debugging ... :-)--
In Section
Seekers of Perl Wisdom
|
|