Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023306]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-03-28 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (326 votes). Check out past polls.