Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
if run as is it prints:use warnings; use strict; use Data::Dumper; my @temp; $temp[12] = q{one two three }; my %hash = ( alias => { map {$_ => risolve( $_ );} split / /,$temp[12] }, ); sub risolve{ my $host = shift; open DNS, "ping -l o -n 1 $host >nil|"||die; while (<DNS>) {1} ### COMMENT THIS LINE AND IT WORKS close DNS; return q{four five six}; } print Dumper \%hash;
and it warns$VAR1 = { 'alias' => { '' => 'four five six' } };
but if you comment out the line while (<DNS>) {1} it prints as expected:Use of uninitialized value in anonymous hash ({}) at wsfp-scratchpad2. +pl line 11. Use of uninitialized value in anonymous hash ({}) at wsfp-scratchpad2. +pl line 11. Use of uninitialized value in anonymous hash ({}) at wsfp-scratchpad2. +pl line 11.
what is happening?$VAR1 = { 'alias' => { 'three' => 'four five six', 'one' => 'four five six', 'two' => 'four five six' } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem with $ARG
by Random_Walk (Prior) on Feb 05, 2009 at 10:56 UTC | |
by tweetiepooh (Hermit) on Feb 05, 2009 at 16:01 UTC | |
by ikegami (Patriarch) on Feb 05, 2009 at 16:11 UTC | |
|
Re: problem with $ARG
by linuxer (Curate) on Feb 05, 2009 at 10:59 UTC |