priyankgandhi has asked for the wisdom of the Perl Monks concerning the following question:
In the above code instead of using if-else conditions can I use something like $$type{$key} / $"$type"{$key} ?my %citystate; my %citycountry; my %country; my %airportCode; my %geonameid; if ($line =~ /.*Cannot find valid (destination) for type:(.*)=(.*)/) { my $type = $2; my $key = $3; if ($type =~ /citystate/) { $citystate{$key} = ""; } elsif ($type =~ /citycountry/) { $citycountry{$key} = ""; } elsif ($type =~ /country/) { $country{$key} = ""; } elsif ($type =~ /airportCode/) { $airportCode{$key} = ""; } elsif ($type =~ /geonameid/) { $geonameid{$key} = ""; } } 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>"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamic hash name
by Tanktalus (Canon) on Feb 03, 2009 at 00:26 UTC | |
by priyankgandhi (Novice) on Feb 03, 2009 at 00:38 UTC | |
by ikegami (Patriarch) on Feb 03, 2009 at 01:34 UTC | |
|
Re: dynamic hash name
by toolic (Bishop) on Feb 03, 2009 at 00:25 UTC |