Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Assigning an array to a scalar

by hostyle (Scribe)
on Sep 25, 2004 at 18:16 UTC ( [id://393823]=note: print w/replies, xml ) Need Help??


in reply to Assigning an array to a scalar

My poor effort. Seeing as map was already used I went for while / shift.
while ($_ = shift @letters) { $word .= $_; }
I thought shift should return the array element, so why do I need to use $_ = shift ... ?

Replies are listed 'Best First'.
Re^2: Assigning an array to a scalar
by ysth (Canon) on Sep 26, 2004 at 06:53 UTC
    I thought shift should return the array element, so why do I need to use $_ = shift ... ?
    Because the implied $_ = in a while condition only happens for readline aka <>.

    Also, with shift you don't get the implied defined() around the while condition; if one if the elements of @letters is "0", the loop will stop early. Try while (defined($_ = shift @letters))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-26 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found