in reply to Double interpolation of captured substrings
You can do away with the hash completely by passing the order as a list rather than a string.
#! perl -slw use strict; sub munge { my( $str, $regex ) = ( shift, shift ); my @matches = ( undef, $str =~ $regex ); return join'', @matches[ @_ ]; } print munge( 'one_two_three', '^([^_]+)_([^_]+)_([^_]+)$', 2, 1, 3 ); __END__ [10:24:12.59] P:\test>junk twoonethree
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Double interpolation of captured substrings
by Fletch (Bishop) on Nov 17, 2004 at 16:59 UTC |