in reply to dynamic hash name

You can, but it involves symbolic references that you really shouldn't bother with until you know why.

Instead, you need a symbol table of your own. Either:

my %destinations; if ($line =~ /.*Cannot find valid (destination) for type:(.*)=(.*)/) { $destinations{$type}{$key} = ""; }
or
my %citystate; my %citycountry; my %country; my %airportCode; my %geonameid; my %symboltable = ( citystate => \%citystate, citycountry => \%citycountry, country => \%country, airportCode => \%airportCode, geonameid => \%geonameid ); if ($line =~ /.*Cannot find valid (destination) for type:(.*)=(.*)/) { $symboltable{$type}{$key} = "" }
The first option is better. (Advanced monks may disagree, but for beginners, it simply is better. You can learn the second way when you really understand the first way and its limitations.)

Replies are listed 'Best First'.
Re^2: dynamic hash name
by priyankgandhi (Novice) on Feb 03, 2009 at 00:38 UTC
    So for the first option: How do I iterate? Because at the end this is what I want to do.
    for my $key ( keys %citystate ) { $fhdest -> print("<p>$key</p>"); } for my $key ( keys %citycountry ) { $fhdest -> print("<p>$key</p>"); } for my $key ( keys %airportCode ) { $fhdest -> print("<p>$key</p>"); }
      $data{citystate} contains a reference to a hash, so where you had
      for my $key ( keys %citystate ) {
      you now use
      for my $key ( keys %{ $data{citystate} } ) {