in reply to Using a regex function from a hash

Because there is no built-in regexp-based lookup into a hash, the regexps might as well be paired with a reference to the code for each regexp, a.k.a a 'dispatch table':
my @dispatch = [ [ '\.vms', sub { my $fnam = shift; $fnam =~ s/\///g; return $fnam; } ] # ,[] ... ]; for ( my $v=0; $v <= $#view; $v++ ) { REGEXP: for ( my $d=0; $d <= $#dispatch; $d++ ) { if ( $view[$v] =~ /$dispatch[ $d ][0]/ ) { $view[$v]=&{$dispatch[$d][1]} ($view[$v]); last REGEXP; } } }
(updated to correct a typo - see reply below)

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Using a regex function from a hash
by Anonymous Monk on Aug 03, 2006 at 17:34 UTC
    This makes the most sense to me, but, I think this line:
    $view[$v]=&{$dispatch[$d][0]} ($view[$v]);
    should probably be this
    $view[$v]=&{$dispatch[$d][1]} ($view[$v]);
      absolutely - well spotted!

      -M

      Free your mind