HomePage RecentChanges Evil Perl

Well... Perl is not evil, but there is some Perl that can cause some unusual behaviour.

What perl is Evil?

What is the downside of using them

Performance... well lack of. For large regular expressions.

#!Perl
my $count = 0;
while (1) {
        $count++;
        if ($text =~ /\G([^<]+)/gcs) {
        } elsif ($text =~ /\G<!--(.*?)-->gcs) {
        } elsif ($text =~ /\G<\?xml(.*?)\?>gcs) {
        } elsif ($text =~ /\G<\?(.*?)\?>gcs) {
        } elsif ($text =~ /\G<(.*?)(\/)?>gcs) {
        } else {
                last;
        }
}

Quick Perofrmance Test

$ time perl test.pl 
Fake loop start - size 488606
Fake loop end - for 21583

real	0m0.073s
user	0m0.068s
sys	0m0.005s

$ time perl test.pl  evil
Fake loop start - size 488606
Fake loop end - for 21583

real	0m12.830s
user	0m5.558s
sys	0m7.266s

Quick Perofrmance Test

175 times slower

Alternatives

e.g. To get the end of the string not matched

#!Perl
	# OLD
	$test =~ /OSDC2007/;
	$rest = $&;

	# NEW
	$test =~ /OSDC2007(.*)$/;
	$rest = $1;

It's not all good news

Using brackets to capture...

So use it ?

Testing Code

Modules effected

There are bound to be more...

Talk History

Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.