Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: looking for a perl way to build a hash

by choroba (Abbot)
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.

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


Comment on Re: looking for a perl way to build a hash
Select or Download 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2014-07-28 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (200 votes), past polls