Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I tried the string convert to hash in the following format.
$string="1:one;2:two;3:three";
%hash=(1=>"one", 2=>"two", 4=>"three");
I wrote the code below, but not getting the above hash. Kindly let me know what is the issue, and solution.
use Data::Dumper; %hash = (split /\:/, (split /;/ $string)); print Dumper \%hash;
now getting output is:
$VAR1 = { '3' => undef };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Split string into hash
by davido (Cardinal) on Feb 10, 2011 at 06:30 UTC | |
Re: Split string into hash
by andreas1234567 (Vicar) on Feb 10, 2011 at 06:19 UTC | |
Re: Split string into hash
by Anonymous Monk on Feb 10, 2011 at 06:20 UTC | |
Re: Split string into hash
by chrestomanci (Priest) on Feb 10, 2011 at 11:11 UTC | |
Re: Split string into hash
by locked_user sundialsvc4 (Abbot) on Feb 10, 2011 at 15:00 UTC |