Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 (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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://957226]
Discipulus another oneliner for my quiver, if a silly one
[marto]: Beware the one liner :p

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-09-22 08:24 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (260 votes). Check out past polls.