Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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"; }

Replies are listed 'Best First'.
Re^3: Memory Leaks and %+
by BrowserUk (Patriarch) 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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2022-09-30 07:03 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.