Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: interleave two arrays

by kloro2006 (Initiate)
on Feb 02, 2014 at 23:07 UTC ( [id://1073099]=note: print w/replies, xml ) Need Help??


in reply to interleave two arrays

#the following gives: a 1 b 2 c 3 @arr1 = qw(a b c); @arr2 = qw(1 2 3); while (@arr1) {push @arr3, shift @arr1,shift @arr2} print "@arr3"; #BUT why does the following give an infinite loop? @arr1 = qw(a b c); @arr2 = qw(1 2 3); while ($push @arr3, shift @arr1,shift @arr2){}

Replies are listed 'Best First'.
Re^2: interleave two arrays
by choroba (Cardinal) on Feb 02, 2014 at 23:11 UTC
    See the documentation of push:
    Returns the number of elements in the array following the completed "push"

    Also, remove the dollar sign before "push".

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      thanks. how do i edit an item i've already posted?

Log In?
Username:
Password:

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

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

    No recent polls found