|
|
| XP is just a number | |
| PerlMonks |
chop() and list assignmentsby converter (Priest) |
| on Mar 06, 2001 at 02:05 UTC ( [id://62423]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.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
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||