Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: list to LoL

by Maqs (Deacon)
on Jun 02, 2000 at 21:53 UTC ( #16077=note: print w/ replies, xml ) Need Help??

in reply to list to LoL

Below is Adam's modified version. It seemed to be working well

my @a = (1,2,3,4,5,6,7,8,9,10,11,12); my $n = 4; #parameter my @lol; while (@a){ @lol = (@lol, [splice @a, 0, $n]); $i=$i+$n; }; print "$lol[2][2]\n"; #for example


Comment on Re: list to LoL
Download Code
RE: Re: list to LoL
by Adam (Vicar) on Jun 03, 2000 at 03:19 UTC
    I don't know why you are crediting me with that code, I didn't write it. I see no advantages to it except that it eliminates the need to call reverse(). It also has a useless $i (which $^W doesn't warn you about because you do it twice. Mine has that warning but its easily circumvented - after all you know it isn't a typo). Mine uses $i to avoid steping on the refs (note that @A is both the source and destination in my version). It still destroys @A because splice does that. The only way to preserve the original is make a back up copy.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-04-02 04:00 GMT
Find Nodes?
    Voting Booth?

    Who makes your decisions?

    Results (57 votes), past polls