> And is this method any faster or more efficient than this?
>
> $var =~ s/\{([^}]+)\}/$v = $1; $v =~ s!,!|!g; qq!($v)!/ge;
Why not find out yourself?
C:\src\perl>type rebench.plx
use strict;
use Benchmark qw/cmpthese/;
sub luke
{
my $var = 'blargh{a,b,c}';
my $v;
$var =~ s/\{([^}]+)\}/$v = $1; $v =~ s!,!|!g; qq!($v)!/ge;
}
sub john
{
my $var = 'blargh{a,b,c}';
$var =~ s<{([^}]+)}><(?:@{[ ($a = $1) =~ y/,/|/ && $a ]})>;
}
cmpthese(100000, {
'Luke' => \&luke,
'John' => \&john
});
C:\src\perl>rebench
Rate John Luke
John 59809/s -- -21%
Luke 75301/s 26% --
Also, switching the s!,!|!g to a y!,!|! in mine is faster yet:
C:\src\perl>rebench2.plx
Rate John Luke
John 59242/s -- -32%
Luke 87642/s 48% --
Of course, unless you're doing 100000 substitutions in your program, the
speed difference doesn't matter at all :-)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>