On Sat, 2006-15-04 at 09:32 -0400, Steve Bertrand wrote:
> Just out of curiosity, if you pass the hash, won't it create a 'copy' of
> the original, manipulate it so that in the end you may have two
> different versions (modifications) of the same hash?
>
> As I understand it, if you pass a href, then you actually work with the
> original hash without making a copy? Do I understand this right?
>
> Steve
>
>
No, when Perl passes a hash, it converts it into a list. This list is
disassociated with the hash. Any changes in the subroutine will not
effect the original, unlike arrays:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
my @a = qw/ a b c d e f /;
print Dumper [EMAIL PROTECTED];
foo( @a );
print Dumper [EMAIL PROTECTED];
my %h = (
a => 1,
b => 2,
c => 3,
);
print Dumper \%h;
foo( %h );
print Dumper \%h;
sub foo {
for ( @_ ){
tr/aeiou/AEIOU/;
}
}
--
__END__
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>