|XP is just a number|
chop() and list assignmentsby converter (Priest)
|on Mar 06, 2001 at 07:05 UTC||Need Help??|
converter has asked for the
wisdom of the Perl Monks concerning the following question:
Someone on DALnet #perl challenged the channel to come up with the shortest subroutine to return the last character of its argument(s). I thought about it for a few seconds, and replied with:
This works as expected when foo() is passed a single scalar argument, but when foo() is passed a list, rather than returning the last character of the last list element as one would expect after reading the documentation on chop()*, it returns the last character of the first element in the list.
Changing foo() to:
makes foo() work as expected.
Is this a documented behavior? I am probably missing some simple concept involved in list assignments, but I'd like to know why the list assignment has this effect.
*from perlfunc: If you chop a list, each element is the chopped. Only the value of the last `chop' is returned.
edit: chipmunk on 2001-03-05