The use of this variable anywhere in a program imposes a considerable performance penalty on all regular expression matches. See "BUGS"....but in the BUGS section it states that:
Due to an unfortunate accident of Perl's implementation, use English imposes a considerable performance penalty on all regular expression matches in a program,[...]now i'm confused :) ... i don't understand wheter use English; (i.e. $POSTMATCH) reduces performance or simply using $'.
Both. Read the section on performance in perldoc English
Basically, using $`, $&, and $' impose a performance penalty on all regular expression matches. Because the English module makes use of these vars, it too imposes the same performance penalty.
#!/usr/bin/perl
use strict;
use Data::Dumper;
my $line = q[keyword1 value keyword2 "value with spaces" keyword3 value];
print Dumper tokenize_line($line);
sub tokenize_line {
my $line = shift;
my @tokens;
while ($line =~ /(\S+)/g) {
# every non-space match is a token
push @tokens, $1;
# anything in double-quotes is a single token
if ($line =~ /\G\s*"(.+?)"/) {
push @tokens, $1;
# continue from this last match
$line = $';
}
}
return \@tokens;
}
wich outputs this:
$VAR1 = [
'keyword1',
'value',
'keyword2',
'value with spaces',
'keyword3',
'value'
];
i know it's an ugly hack, trying to substitute the original string with the rest of the matched pattern ($line = $';), but in my previous attempts i would use split and substr to achieve the same results... and it was very ugly :)use English qw(-no_match_vars);
perlmonks.org content © perlmonks.org and Aristotle, asz, duff, ikegami, monkey_boy
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03