Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: looking for a perl way to build a hash

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


#!/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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-11-25 04:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (670 votes), past polls