consider this
which yields this outputsub pass_var { my ($foo,$bar) = @_; print "foo: $foo bar: $bar\n"; $foo = 'c1'; $bar = 'c2'; print "changed: foo: $foo bar: $bar\n"; } sub pass_ref { my ($hash) = @_; print "hash: $hash->{'key'}\n"; $hash->{'key'} = 'c1'; print "changed: hash: $hash->{'key'}\n"; print "hashref is: $hash\n"; } my $hash; my $foo; my $bar; $foo = 1; $bar = 2; $hash = {'key' => 1 }; &pass_var($foo,$bar); print "after: foo: $foo bar: $bar\n"; &pass_ref($hash); print "after: hash: $hash->{'key'}\n"; print "hashref is: $hash\n";
See how the hash both in and out of the sub point to the same memory address?foo: 1 bar: 2 changed: foo: c1 bar: c2 after: foo: 1 bar: 2 hash: 1 changed: hash: c1 hashref is: HASH(0x80f86e0) after: hash: c1 hashref is: HASH(0x80f86e0)
/\/\averick
In reply to Re: How does my $self = (@_) actually work?
by maverick
in thread How does my $self = (@_) actually work?
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |