Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: references best practice

by Haarg (Chaplain)
on Apr 25, 2008 at 22:51 UTC ( #682947=note: print w/ replies, xml ) Need Help??


in reply to Re: references best practice
in thread references best practice

Your second example isn't doing what you intend. The array outside of the sub isn't modified. The first line of prepData2 sets $refData to the incoming reference. The second replaces that reference with a different one, leaving the contents of the first reference unchanged. You'd want something more like:

sub prepData2 { my $refData = shift; @$refData = map { log $_ } 1 .. 100; }
With that change, the benchmark changes somewhat, making it almost identical to array_ref_out1 in my tests.


Comment on Re^2: references best practice
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2014-12-18 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (50 votes), past polls