Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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


Comment on Re: qw() and lists of lists
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-07-29 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls