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