On 8/3/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > 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; snip
Note that my advice is to use $hash3{"@key"} Which does not suffer from that problem and that I specifically said "you don't want the spaces that using an array slice will add". -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/