Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: qw() and lists of lists

by davido (Archbishop)
on Mar 13, 2013 at 22:07 UTC ( #1023306=note: print w/replies, xml ) Need Help??

in reply to qw() and lists of lists

One way is with pairwise.

use List::MoreUtils qw( pairwise ); my @nametape = pairwise{ [ $a, $b ] } qw( 24 101 25 102 23 103 );

Update, correction: pairwise accepts a block and two lists. Doh!

What I was really after was the natatime function (also in List::MoreUtils):

use List::MoreUtils qw(natatime); my @list = qw( 24 101 25 102 23 103 ); my $it = natatime 2, @list; my @pairs; while ( my @vals = $it->() ) { push @pairs, \@vals; }

But frankly, the premise bugs me. It seems silly to jump through coding hoops and a runtime loop just to avoid typing [ 1,2 ], into the source code, in favor of qw( ... ). It doesn't improve code clarity, and doesn't improve code efficiency.

Thanks kcott for noticing and pointing out to me my mistakes. My defense: The two year old was throwing a fit while I typed the original solution. I think a screaming 2-year-old is probably more of a cognitive impairment than a few stiff drinks... but since I don't drink I'm probably not qualified to make the comparison.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023306]
[shmem]: but! perl4 doesn't suck.
[LanX]: better try 3
[shmem]: that python stuff is none of my business.
[shmem]: but sometimes I have to debug things implemeted by "the other team" and stick their nose into their dirt.
[shmem]: because it affects "my team"
[shmem]: ah well... git is incomplete. There are commands missing:
[shmem]: git stop crap
[shmem]: for instance

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-03-20 18:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (257 votes). Check out past polls.