Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Way to do a "scalar ref"?

by doug (Pilgrim)
on Sep 26, 2011 at 17:14 UTC ( #927905=note: print w/ replies, xml ) Need Help??


in reply to Way to do a "scalar ref"?

You can explicitly pass a reference if you like, or you can use the dark voodoo of prototypes. You could define

sub test(\$) { my ($scalar_ref) = @_; $$scalar_ref =~ tr/a-m/N-Z/; substr($$scalar_ref, 0, 0) = "prepended sumthin'"; }

and it should do what you want. Just make calls like

test($t)

until your heart is content. You just have to make sure that test(\$) is seen before making the call. And be careful what you pass as an argument to test() because prototypes can work differently than you think they should.


Comment on Re: 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://927905]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (15)
As of 2015-07-07 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (89 votes), past polls