That helps a lot, thanks. I don't often use references, especially to
anonymous things. I'm used to it being a reference to a "real" hash, like

my $hashref = \%hash;

Thanks for the clarification!




> -----Original Message-----
> From: Thomas, Mark - BLS CTR [mailto:[EMAIL PROTECTED]
> Sent: Thursday, March 17, 2005 12:52 PM
> To: 'Peter Eisengrein'; [email protected]
> Subject: RE: copying structures
> 
> 
> Peter Eisengrein wrote:
> 
> > OK, I sort of get it. But what hash is it a reference to? If 
> > you wanted to
> > access or modify the hash directly where is it?
> 
> You can modify it through either reference. Maybe the 
> following code will
> help you. Other references are 'perldoc perldata', 'perldoc perldsc',
> Learning Perl, etc.
> 
> #---
> 
> my $hashref1 = { foo => 'bar' };
> 
> my $hashref2 = $hashref1;
> 
> # Only the reference is copied
> print $hashref1->{foo}; # prints "bar"
> print $hashref2->{foo}; # prints "bar"
> 
> # You can use either reference to modify the hash
> $hashref2->{foo} = 'baz';
> 
> print $hashref1->{foo}; # prints "baz"
> print $hashref2->{foo}; # prints "baz"
> 
> my %newhash = %$hashref1; #dereferenced, therefore values are copied
> 
> $hashref1->{foo} = 'qux';
> 
> print $hashref1->{foo}; # prints "qux"
> print $hashref2->{foo}; # prints "qux"
> print $newhash{foo}; # still prints "baz"
> 
> #---
> 
> 
> 
> 
> __________________________________________________________
> This message was scanned by ATX
> 12:52:33 PM ET - 3/17/2005
> 
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to