Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: interleave two arrays

by gryng (Hermit)
on Feb 03, 2001 at 02:43 UTC ( [id://56131]=note: print w/replies, xml ) Need Help??


in reply to interleave two arrays

Just an alternate way:

sub interleave { my $y; while (@{ $_[0] } or @{ $_[1] }) { push @$y, shift @{ $_[0] } if @{ $_[0] }; push @$y, shift @{ $_[1] } if @{ $_[1] }; } return $y; }
Ack, what have I done, this will surely lead to endless perl golf!

Ciao,
Gryn

Update: Eek, this doesn't work. Please ignore -- I'm at work and will be a while to fix.

Update: Ok that seems better. Thank you for your patience :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found