in reply to Regex Substitution in sub

If your codes are that exact, do a hash lookup instead:

sub interpret_clock { my %codes = ( '43 F' => 'Tunnel 1/2 Hr FT', '43 P' => 'Tunnel 1/2 Hr PT', '45 F' => 'Tunnel No Lunch FT', '45 P' => 'Tunnel No Lunch PT', 'F' => 'Full Time No Clock', 'O' => 'On Call No Clock', 'P' => 'Part Time No Clock', 'T' => 'Temporary No Clock', ); my $code = shift; unless (exists $codes{$code} ) { die "Unknown code: ($code)"; } return $codes{$code}; }

You're much less likely to be in error with that.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Replies are listed 'Best First'.
Re: Re: Regex Substitution in sub
by Juerd (Abbot) on Jun 04, 2003 at 18:51 UTC

    sub interpret_clock { my %codes = (

    It is probably a good idea to build the hash outside the sub, to avoid building it each time the sub is called.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      Oops. You're right. Some days it doesn't pay to chew through the straps and log on.

      Cheers,
      Ovid

      New address of my CGI Course.
      Silence is Evil (feel free to copy and distribute widely - note copyright text)