you're a php guy, right?<br>
<br>
$x = (); is a list assignment to a scalar. scalar conversion
results in the scalar ($x that is) being assigned the count of the
number of items in the list. 0 or zero.<br>
<br>
$x = {}; assigns a reference to an anonymous hash.<br><br><div><span class="gmail_quote">On 4/10/07, <b class="gmail_sendername">Fulko Hew</b> <<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 4/10/07, Fulko Hew <<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>> wrote:
<br>> I always seem to have a problem dereferencing anonymous hashes...<br>> (a mental block, or I'm just mental!)<br>><br>> In a subroutine I create the thing as such:<br>><br>> sub foo {<br>>
my $device =
{};
# create an anonymous hash<br>> $config{$cfg}{device} = \$device; # And stick it into the major data structure<br>><br>> $device{$devId}{status) = 'ok'; # and populate the anonymous hash<br>
> $device{$devId}{msgCnt}++;<br>> }<br>><br>> Then later on I want to extract the status:<br>><br>> my %device = ${$config{$cfg}{device}};<br>> $status = $device{$devId}{status};<br>><br>> but this isn't quite right. ;-(
<br><br>Answering my own question...<br>I was close, but not cigar. What I should have been using was:<br><br>my $device = ();<br> ...<br>my %device = %{$config{$cfg}{device}};<br><br>because the reference I was trying to retrieve was a reference to a hash,
<br>not a reference to a scalar as in my first 'n' tries.<br><br>I'm sure I had the dereference correct a number of times, but without<br>the anonymous hash creation correct at the same time, It didn't<br>
work.... Nope, I just tried it as: my $device = {}; and that still<br>worked. It makes me wonder then... whats the subtle difference<br>between<br>$x = () and $x = {} when dealing with hashes and their references?<br>_______________________________________________
<br>toronto-pm mailing list<br><a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br></blockquote></div>
<br>