http://www.perlmonks.org?node_id=1046521


in reply to looking for a perl way to build a hash

TIMTOWTDI:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $str1 = 'a,b,c'; my $str2 = '1,2,3'; my ($strA, $strB) = ($str1, $str2); $strA =~ s/,/',' . do { $strB =~ s=([^,]+),==; $1 } . ','/eg; my %hash2 = split /,/ => "$strA,$strB"; print Dumper \%hash2;

Update: Or, without a regex:

my ($strA, $strB) = ("$str1,", "$str2,"); my %hash = map { map substr($_, 0, -1), map substr($_, 0, 1 + index($_, ','), q()), $strA, $strB; } 1 .. $strA =~ tr/,//; print Dumper \%hash;

Not recommended for production code.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ