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

Re: deferencing an hash in a subroutine

by moritz (Cardinal)
on Aug 20, 2010 at 15:06 UTC ( [id://856295]=note: print w/replies, xml ) Need Help??


in reply to deferencing an hash in a subroutine

sub test { for (my $i = 0; $i < @_; $i += 2) { if ($_[$i] eq 'a') { $_[$i+1] = 'found a'; } } } my $a = 'not found'; test b => 3, a => $a; print "$a\n";

But beware, chaning your caller's arguments is evil, and usually produces code that's hard to understand and read.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: deferencing an hash in a subroutine
by saintex (Scribe) on Aug 20, 2010 at 15:13 UTC
    and if I try to forse at the end of my sub:
    $_[0]=\%q;

    It will overwrite the previous hash reference. is it correct?
      $_[0]=\%q; sets the first argument on the caller side to \%q. Which only makes sense if you pass a scalar variable as first argument.

      Maybe it would be more helpful if you wrote what the underlying reason is for doing what you try to do. Maybe that way we can suggest a better solution. See also XY Problem.

      Perl 6 - links to (nearly) everything that is Perl 6.
        ok, there is an update on my first post.
        thank you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-23 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found