Welcome to the Monastery | |
PerlMonks |
Re: Uninitialized value warning in subrutineby olivierp (Hermit) |
on Jan 29, 2005 at 09:18 UTC ( [id://426209]=note: print w/replies, xml ) | Need Help?? |
I assume you would like to access the last element of the implicit @_ array. Note that @_ and $_ are 2 different variables, as @var and $var are. In a sub, @_ represents the arguments that you passed in, and this is what you should be accessing, whereas $_ is the "default" variable used/created in various looping constructs, the "default" match target , amongst others, as infor (@array){ print $_ if /hello world/i} Your "Use of uninitialized value in substraction (-)" comes from trying to substract 1 from the $_ variable, which is undefined in the sub, when you actually would like to substract 1 from the number of items in @_ Here are 3 ways of achieving what you are looking for:
For further info on predefined variables, as $_ and @_ check out perlvar
HTH -- Olivier
In Section
Seekers of Perl Wisdom
|
|