| [reply] |
perldoc -f chomp
chomp( LIST )
If you chomp a list, each element is chomped, ...
| [reply] [d/l] |
Soren is right. The reason this works is that the array is evaluated in a list context - each row is sent to chomp. Which is the same reason, I believe, that foreach( @array ) processes each row of an array.
Context is a central concept in Perl. It's one of the reasons that you don't have to code the sort of detail needed in many other programming languages.
| [reply] |
the array is evaluated in a list context.
Huh, it sounds a bit like a tautology, doesn't it? (Even though an array may be evaluated in a scalar context and return in this case the number of elements.)
I would rather say that the array is imposing a list context and that the chomp operator is used in a list context in this case. And, in such a case, it chomps all the elements of the list (and returns the total number of characters removed)
Note that if used on a hash, it chomps the hash's values, but not its keys.
| [reply] |
> I would rather say that the array is imposing a list context and that the chomp operator is used in a list context in this case.
nope, you're wrong. the operator chomp imposes the context, thats how scalar @array works.
I think @array can only impose list context as LHS of =, which becomes a list-assignment operator then.
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] [d/l] [select] |