Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Way to do a "scalar ref"?

by moritz (Cardinal)
on Sep 26, 2011 at 09:02 UTC ( #927826=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Way to do a "scalar ref"?
in thread Way to do a "scalar ref"?

FWIW @_ and thus $_[0] are already aliases to the variable used in the call, so if you do something like

sub f { $_[0] =~ s/a/b/g } my $text = 'foo bar' f $text

No copying happens.

If you want explicit references, do it like this:

sub f { my $ref = shift; $$ref =~ s/a/b/g } my $text = 'foo bar' f \$text
m working on a wiki (which can have VERY large articles in). The site also gets a lot of traffic (several million hits a month), so I need to make this code as optimized as possible.

Then be sure to read perlperf, and cache wherever possible. If you cache the rendered version of very large articles, the number of renderings becomes proportional to the number of writes, which is usually much lower than the number or reads.


Comment on Re^3: Way to do a "scalar ref"?
Select or Download Code

Log In?
Username:
Password:

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

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

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (195 votes), past polls