in reply to Does Perl do constant anonymous hash creation optimisation?
Even if Perl did detect the constant nature of the inline hashes, which I seriously doubt it could, something like this is probably clearer
use constant { SUBSTITUTES => { # substitute these 'DUTCH' => 'NETHERLANDS', 'GERMANY' => 'DEUTSCHLAND', 'AUST.' => 'AUSTRALIA', }, SKIPWORDS => { # skip these 'BANK' => 1, 'CORP' => 1, 'GOVERNMENT' => 1, 'GOVT' => 1, 'LIMITED' => 1, 'LTD' => 1, 'NPV' => 1, 'COM' => 1, }, }; sub words { return [ map { SUBSTITUTES->{$_} or $_ } grep { !SKIPWORDS->{$_} } split /\s+/, shift ]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Does Perl do constant anonymous hash creation optimisation?
by jaa (Friar) on Jul 08, 2006 at 14:21 UTC | |
by BrowserUk (Patriarch) on Jul 08, 2006 at 15:53 UTC | |
by jaa (Friar) on Jul 08, 2006 at 17:34 UTC | |
by jaa (Friar) on Jul 10, 2006 at 15:06 UTC |