Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Simple Pass By Reference

by tomazos (Deacon)
on Jul 26, 2005 at 00:27 UTC ( [id://478029]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Simple Pass By Reference
in thread Simple Pass By Reference

I kind of wanted to use a local alias for $_[0], rather than have to use a reference that I have to remember to dereference everywhere.

I guess I just want to say:

alias $var_in_sub = $_[0];

Just to give $_[0] a meaningful name in the context of the subrountine, such that $var_in_sub and $_[0] are the same thing. In the same way as $var_elsewhere and $_[0] are the same thing when calling alter_var($var_elsewhere).

I guess this can't be done in Perl, without using references and dereferencing - which is fine. No big deal.

-Andrew.


Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

Replies are listed 'Best First'.
Re^5: Simple Pass By Reference
by sk (Curate) on Jul 26, 2005 at 00:57 UTC
    Wouldn't this be considered to be semi-alias? Well you create one more variables but still does not have the "contents" as it is still a pointer/reference. So memory is OK here?

    sub alter_var { my $aliasvar = $_[0]; # Nice to have C like proto types but... ${$aliasvar} =~ s/a/b/g; # ${$_[0]} =~ s/a/b/g; # This uses $_[0] and works }
Re^5: Simple Pass By Reference
by PodMaster (Abbot) on Jul 26, 2005 at 00:52 UTC
    I guess this can't be done in Perl, without using references and dereferencing - which is fine. No big deal.
    Someone always has to dereference. I'm not sure, but I think you're after one of the alias modules (Lexical::Alias, Tie::Alias, Variable::Alias, Data::Alias).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found