Re: Problem with my code
- From: shawnhcorey@xxxxxxxx (Mr. Shawn H. Corey)
- Date: Fri, 03 Aug 2007 10:10:58 -0400
Chas Owens wrote:
The use of the special variable $; is not why
$foo{$a[1],$a[2],$a[3],$a[4]} is a bad choice; it is a bad choice
because it is hard to tell if they meant to use
@foo{$a[1],$a[2],$a[3],$a[4]} but screwed up the sigil. The spaces
are only important if you want to recover the individual values from
the key, and, since you are storing the entire record, you don't even
need the key to get those values. Why would you create a nested hash?
This does not appear to be a tree data. If you want to do it long
hand because you don't want the spaces that using an array slice will
add then simply say
$hash{"{$cdr[2]$cdr[3]$cdr[6]$cdr[7]"}
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %hash1 = ();
my %hash2 = ();
my $key1 = 'ab';
my $key2 = 'c';
$hash1{"$key1$key2"} = 'some value';
$hash2{$key1}{$key2} = 'some value';
print "\%hash1 = ", Dumper \%hash1;
print "\%hash2 = ", Dumper \%hash2;
my $key3 = 'a';
my $key4 = 'bc';
$hash1{"$key3$key4"} = 'some other value';
$hash2{$key3}{$key4} = 'some other value';
print "\%hash1 = ", Dumper \%hash1;
print "\%hash2 = ", Dumper \%hash2;
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
.
- Follow-Ups:
- Re: Problem with my code
- From: Chas Owens
- Re: Problem with my code
- References:
- Re: Problem with my code
- From: Jeff Pang
- Re: Problem with my code
- From: Chas Owens
- Re: Problem with my code
- From: Mr. Shawn H. Corey
- Re: Problem with my code
- From: Chas Owens
- Re: Problem with my code
- Prev by Date: Re: Problem with my code
- Next by Date: Re: Problem with my code
- Previous by thread: Re: Problem with my code
- Next by thread: Re: Problem with my code
- Index(es):