Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Invalid argumentby suaveant (Parson) |
on Dec 01, 2006 at 20:26 UTC ( [id://587292]=note: print w/replies, xml ) | Need Help?? |
Ok.. your use of @_ is just plain wrong, which is your main problem... we'll forgive it since you are learning :)
You use strict and warnings, that is good. @_ is a special variable that Perl uses to provide you with the arguments that were passed to a subroutine. (which is why strict ignores it). What is happening is that you set @_ to two values, you then call handle_fix. Perl then silently replaces the values in @_ with that arguments passed to the subroutine (empty array), and runs the sub. On return Perl restores the old values of @_ and merrily continues along, making you angry :) I would change the code to something more like... Now... keep in mind iterating through @_ and changing $_ directly WILL change the arguments passed to your sub, but is generally not the best practice. It is not obvious that the args are being changed and later that can bite you or someone else maintaining the code... a better way might be... Hope that helps
In Section
Seekers of Perl Wisdom
|
|