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

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?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2016-05-29 08:52 GMT
Find Nodes?
    Voting Booth?