develooper Front page | perl.beginners | Postings from February 2012

Re: perl and pattern

Thread Previous | Thread Next
From:
Igor Dovgiy
Date:
February 23, 2012 03:34
Subject:
Re: perl and pattern
Message ID:
CADGQiHGroMgKMH9bQkKYgsAj2842fn-GU1fJyx5t4Pr=36dB-Q@mail.gmail.com
2012/2/23 Rob Dixon <rob.dixon@gmx.com>

>
> Negative numbers aside, it seems more straightforward to insist that
> there are no non-digit numbers in the input, hence
>

That's definitely an option, but I'm not in favor of 'double negation'
conditionals usually, as they might be confusing.
For example, I use <unless> only when its question is simple and... a kind
of predictable. Like that:

exit unless $result =~ /^[0-9]+$/

That's definitely an overkill for me:

unless ($result !~ /[^0-9]/) { ... }

...especially because it can be safely turned to ...

if ($result =~ /[^0-9]/) { ... }

As for /\D/, well, I'd prefer to use it only with /a modifier, the reasons
discussed earlier at this thread. )

-- iD


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About