Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: looking for a perl way to build a hash

by choroba (Chancellor)
on Jul 26, 2013 at 14:11 UTC ( #1046521=note: print w/replies, xml ) Need Help??


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.

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2016-12-09 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (151 votes). Check out past polls.