in reply to syntax for hashes with variable in name
Your immediate problem is that perl interprets your %{ as a hash slice (see http://docstore.mik.ua/orelly/perl/learn/ch05_05.htm for a small example)
Your larger problem is that you want to use a technique that is a relict from perl4 days and only (if at all) suitable for quick hacks
Instead of using
use multidimensional hashesmy %{"platform_$site"}; ${"platform_$site"}{"thingy"}= 5; foreach my $x ( keys %{"platform_$site"}) { ...
my %platform; $platform{$site}{"thingy"}= 5; foreach my $x ( keys %{$platform{$site}}) { ...
You can use the same technique for your arrays as well, i.e. use a so called HashOfArrays:
push @{$platform{$site}}, 1,2; $platform{$site}[5]= 5; foreach my $x ( @{$platform{$site}}) { ..
PS: I also notice you don't use 'use warnings;' and 'use strict;' at the beginning of your script. It is highly advisable to include those two lines. Avoids many bug finding sessions later.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: syntax for hashes with variable in name
by ikegami (Patriarch) on Nov 22, 2010 at 17:18 UTC | |
|
Re^2: syntax for hashes with variable in name
by ambrus (Abbot) on Nov 22, 2010 at 13:55 UTC | |
by Tux (Canon) on Nov 22, 2010 at 16:46 UTC | |
by jethro (Monsignor) on Nov 22, 2010 at 16:02 UTC | |
|
Re^2: syntax for hashes with variable in name
by equick (Acolyte) on Nov 22, 2010 at 13:06 UTC |