Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Memory Leaks and %+

by ruzam (Curate)
on Mar 01, 2012 at 14:07 UTC ( #957226=note: print w/ replies, xml ) Need Help??


in reply to Re: Memory Leaks and %+
in thread Memory Leaks and %+

Isn't it easier to just switch over to $1 and $2 at this point? Your new substr workaround isn't very readable (to me anyway), so it appears that you've lost the one thing you were hoping to gain by using %+.

my $regexp = qr/(\d+)\s+(\d+)/; while(<$fh>) { next unless /$regexp/; my $value1 = $1; my $value2 = $2; print "GOT $value1 $value2\n"; }


Comment on Re^2: Memory Leaks and %+
Download Code
Re^3: Memory Leaks and %+
by BrowserUk (Pope) on Mar 01, 2012 at 15:16 UTC

    I completely agree yours is more readable that the OPs alternate version. But even more readable is:

    my $regexp = qr/(\d+)\s+(\d+)/; while(<$fh>) { my( $value1, $value2 ) = /$regexp/ or next; print "GOT $value1 $value2\n"; }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://957226]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-07-10 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (209 votes), past polls