Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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


Replies are listed 'Best First'.
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2018-03-22 16:17 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (279 votes). Check out past polls.