On Wed, Jan 28, 2004 at 09:11:51AM -0800 Sam wrote:
> 4. As for the generalized case, I learned about using refs. Anonymous subs
> also work.
>
> my $re = sub { return /^\s*$/; };
> my $nre = sub { return not &$re; };
> my $expr = $blank ? $re : $nre;
> do ... while (&$expr and not eof);
>
> But I'm not sure which is faster though.
These function-refs look fishy. All they do is carrying out a pattern
match. By using '&$expr' you'll also have perl pass on the current
content of @_ to the function which is wasteful since you are not
interested in the arguments.
In this case you better just use pre-compiled regexes:
my $re = qr/^\s*$/;
my $nre = qr/\S/; # !qr/^\s*$/ wont work unfortunately
my $pat = $blank ? $re : $nre;
do ... while /$pat/o and not eof;
This has the disadvantage that there is no generalized way of negating a
pattern. You have to do that manually. Or you create a slightly more
complicated condition:
do ... while ($blank && /$re/) || !/$re/ and not eof;
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>