Answer by Kjetil S. for perl: Use map and foreach at once?
Use List::MoreUtils 'zip' or add your own since that module is not a core module:sub zip(\@@){map{($_[0][$_-1],$_[$_])}1..@{$_[0]}} my %h = zip @keys, @values;
View ArticleAnswer by Polar Bear for perl: Use map and foreach at once?
Well, the question is not very clear on 'why?' -- same can be achieved with following codeuse strict;use warnings;use Data::Dumper;my $debug = 1;my %h;@h{qw(a b c)} = (1..3);print Dumper(\%h) if $debug;
View ArticleAnswer by Grinnz for perl: Use map and foreach at once?
Populating a hash is simply a matter of assigning a list with alternating keys and values, so you just have to construct the list using the two arrays in an alternating fashion.use strict;use...
View Articleperl: Use map and foreach at once?
I was wondering if it is possible to make a hash assigning its keys and values at once. Or in general use map and for at one line:#!/usr/bin/perl%h = map {$_, $i} qw[a b c] for $i (1..3)But...
View Article
More Pages to Explore .....