sunshine_august has asked for the wisdom of the Perl Monks concerning the following question:
I encounted a strange problem with hash in Perl, I have write a tiny script to demostrate this problem:
and here is the executed result:#!/usr/bin/perl use strict; use warnings; my $heap = {}; $heap->{'172.16'} = 1; print "\$heap->{'172.16'}: $heap->{'172.16'}\n"; print "\$heap->{172.16}: $heap->{172.16}\n"; $heap->{'127.2'}{'127.1.0.2'} = 2; print "\$heap->{'127.2'}{'127.1.0.2'}: $heap->{'127.2'}{'127.1.0.2'}\ +n"; print "\$heap->{127.2}{127.1.0.2}: $heap->{127.2}{127.1.0.2}\n";
What surprise me is that $heap->{'127.2'}{'127.1.0.2'} is not the same as $heap->{127.2}{127.1.0.2}.$heap->{'172.16'}: 1 $heap->{172.16}: 1 $heap->{'127.2'}{'127.1.0.2'}: 2 Use of uninitialized value in concatenation (.) or string at /home/lar +ry/project/sysmonitor/test/testHash2.pl line 28. $heap->{127.2}{127.1.0.2}:
Can anyone give some tips?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What's the difference between $heap->{127.2}{127.1.0.2} and $heap->{'127.2'}{'127.1.0.2'} ?
by tilly (Archbishop) on Dec 22, 2008 at 08:57 UTC | |
by AnomalousMonk (Archbishop) on Dec 22, 2008 at 16:44 UTC | |
by Anomynous Monk (Scribe) on Dec 23, 2008 at 02:28 UTC | |
|
Re: What's the difference between $heap->{127.2}{127.1.0.2} and $heap->{'127.2'}{'127.1.0.2'} ?
by Bloodnok (Vicar) on Dec 22, 2008 at 13:26 UTC | |
|
Re: What's the difference between $heap->{127.2}{127.1.0.2} and $heap->{'127.2'}{'127.1.0.2'} ?
by Anonymous Monk on Dec 22, 2008 at 08:41 UTC | |
by sunshine_august (Scribe) on Dec 22, 2008 at 09:21 UTC |