Re: Load hash from a scalar
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 28 Mar 2008 01:17:58 -0700
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 \%b;
'
$VAR1 = {
'c' => '3',
'a' => '1',
'b' => '2'
};
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Load hash from a scalar
- From: Scooter
- Load hash from a scalar
- Prev by Date: special chars as scalar inside regex
- Next by Date: Re: special chars as scalar inside regex
- Previous by thread: Load hash from a scalar
- Next by thread: RE: Load hash from a scalar
- Index(es):
Relevant Pages
|
|