develooper Front page | perl.perl5.porters | Postings from March 2008

Re: [perl #51568] Scalar::Util::looks_like_number vs. Optimzation in regex?

Thread Previous | Thread Next
From:
Eric Brine
Date:
March 10, 2008 14:14
Subject:
Re: [perl #51568] Scalar::Util::looks_like_number vs. Optimzation in regex?
Message ID:
f86994700803101255x3961ebe4ieb72e1b6d89a3e0@mail.gmail.com
On Mon, Mar 10, 2008 at 6:59 AM, via RT Steffen_Ullrich @ genua. de <
perlbug-followup@perl.org> wrote:

> # New Ticket Created by  Steffen_Ullrich@genua.de
> # Please include the string:  [perl #51568]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=51568 >
>

Don't pass globals (especially, $!, $1 and $@) to functions. Pass a copy
instead. The problem arises because Perl passes arguments by reference (uses
aliasing) and (probably) because looks_like_number changes $3.

The simplest way of making a copy of a string is to interpolate the variable
into quote:
     if ( looks_like_number("$3") ) {

Or avoid using $3 at all
     if ( my ($n) = $x =~m{^\w+[<>](\S+)$} ) {
        if ( looks_like_number($n) ) {

- Eric Brine

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