Re: Load hash from a scalar

2008-03-31 Thread John W. Krahn
sanket vaidya wrote: From: scooter [mailto:[EMAIL PROTECTED] I want to load the value from scalar variable to a hash Example: my $a = "a, 1, b, 2, c, 3"; Now, I need to create a hash %b, which holds values like %b = { a => 1, b => 2, c => 3 }; Here is the code to accomplish your task. u

RE: Load hash from a scalar

2008-03-30 Thread sanket vaidya
Here is the code to accomplish your task. use warnings; use strict; my $a = "a, 1, b, 2, c, 3"; $a =~ s/ //g; #delete spaces from $a my @array = split(",",$a); my %b = ( $array[0] => $array[1], $array[2] => $array[3], $array[4] => $array[5] ); for (keys%b) { print "$_ => $b{$_}\n"; } The

Re: Load hash from a scalar

2008-03-28 Thread John W. Krahn
scooter wrote: I want to load the value from scalar variable to a hash Example: my $a = "a, 1, b, 2, c, 3"; Now, I need to create a hash %b, which holds values like %b = { a => 1, b => 2, c => 3 }; $ perl -le' use Data::Dumper; my $a = "a, 1, b, 2, c, 3"; my %b = $a =~ /[^, ]+/g; print Dumper