Hi Jorg,

a few comments on your code:

On Tue, 21 Jun 2011 15:06:23 +0800
"Jorg W." <jo...@postino.net> wrote:

> 2011/6/21 eventual <eventualde...@yahoo.com>:
> > Hi,
> > Looking at the script below, how do I write a range of 10 to 80 as
> > a regular expression. I tried [10 - 80] but it wont work.
> 
> 
> $ perl -le '$x=70; print "true" if grep {/^$x$/} 10 .. 80'

1. Scanning every element of a range like that would be extremely inefficient
(O(N) instead of O(1)).

2. /^$x$/ would be equivalent to $x eq $_ in this case.

3. Better use List::MoreUtils::any here when you want to convey if it
matches the presence in the list, instead of perldoc -f grep (or
perl-5.10.x-and-above's smart-match operator).

4. You should generally interpolate variables into regular expressions using \Q
and \E . See http://perldoc.perl.org/functions/quotemeta.html .

5. I prefer to use \A for start-of-string and \z for end-of-string instead of
"^" and "$", which are more ambiguous.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/

Real programmers don’t write workarounds. They tell their users to upgrade
their software.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to