http://qs321.pair.com?node_id=77011

deprecated has asked for the wisdom of the Perl Monks concerning the following question:

As some of you may know, I've been grappling with using RE's (which I really prefer to use) in code rather than conditionals which are much easier to read (but ten times slower).

I have come up with a neat idea that I thought would simplify my code, and also still allow me to use regular expressions. Rather than having one 60 character RE handle things, I can break stuff down into smaller RE's and put them in an array and then iterate over them. So while I am not using the full extent of the RE engine, I am also not making perl do backflips for conditionals -- and all my co-workers will be able to read it (because theyre small and simple).

So an example of this is the following sub:

sub isend { my $line = shift; my @terminators = [ qr!#=3D=3D=3D(?:END|end)!, qr!#===(?:END|end)!, qr![-]+_=_NextPart_!, qr!1===(?:END|end)!, qr!#---(?:END|end)!, ]; foreach my $ending (@terminators) { return undef if $line =~ $ending; } return 1; }
Note how cool those qr!!'s line up and are easily readable by almost anyone (yeah I'm proud of myself. *grin*). However, the test is evaluating true every single time, even when there is no reason it should be. When I print them out, I get an array ref, which does seem odd since that would seem to me to resemble this:
@terminators = [ [foo, bar], [baz, bletch] ]; # an array of array refs, right?
rather than what it really is, above. So I'm sure I am missing something stupid here, and I'd really like to use this construct since it seems like such a magical silver bullet for my readbility vs. speed dilemma.

thanks
brother dep.

--
Laziness, Impatience, Hubris, and Generosity.