>I guess my question is: aren't these two equal statements?
>
>  my $hash=\%tmpEntry;
>  my $hash={ %tmpEntry };
>
>This is what I get from the command line:

No, they're not the same.  See below:

-------=======+++++++++++++=======-------

  my $hash = \%tmpEntry;
  
  #creates a new scalar variable that is
  #a reference to %tmpEntry;

-------=======+++++++++++++=======-------

  my $hash = { %tmpEntry };
  
  #creates a new, empty, anonymous hash and inserts
  #the keys and values of %tmpEntry into it.  Then
  #it creates a new scalar variable that is a 
  #reference to the anonymous hash.

-------=======+++++++++++++=======-------

-----Original Message-----
From: Shawn [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 12, 2002 3:13 PM
To: [EMAIL PROTECTED]; Craig Moynes/Markham/IBM
Cc: [EMAIL PROTECTED]
Subject: Re: anonymous reference problems


Hey Jeff,
> >I have a loop, each iteration through the loop the hash %tmpEntry gets a
> >new set of values. And each iteration through the loop I place this hash
> >into another hash, like so:
> >
> >[snip]
> > print "Added entry.\n";
> >$oncall{$tmpEntry{'StartDate'}} =  \%tmpEntry;
> >[snip]
> >
> >tmpEntry is defined outside the loop, because I need to handle the last
> >case outside of the loop. This doesn't work, all the entries end up
> >being the same, because of the reference to the memory location.
> 
> You'll need to use { %tmpEntry } then, instead of \%tmpEntry.

Can you explain the difference between the anonymous hash and the referenced
hash, and why it would make a difference here?

Is it because the anonymous scalar reference does not keep the same memory
space?

I guess my question is: aren't these two equal statements?

  my $hash=\%tmpEntry;
  my $hash={ %tmpEntry };

This is what I get from the command line:

>perl -e "%hash=(1=>'one',2=>'two'); my $hash=\%hash; print $hash,qq~\n~;
$hash={%hash}; print $hash,qq~\n~;"
HASH(0x1ac2db8)
HASH(0x1acf150)

>perl -e "%hash=(1=>'one',2=>'two'); my $hash=\%hash; print %$hash,qq~\n~;
$hash={%hash}; print %$hash,qq~\n~;"
1one2two
1one2two

Shawn


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to