Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: chomp each element of array

by JockoHelios (Scribe)
on Jun 10, 2013 at 11:04 UTC ( [id://1038044]=note: print w/replies, xml ) Need Help??


in reply to chomp each element of array

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.

Dyslexics Untie !!!

Replies are listed 'Best First'.
Re^2: chomp each element of array
by Laurent_R (Canon) on Jun 10, 2013 at 12:38 UTC

    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.

      > 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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1038044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found