Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Need help from the esteemed monks on scoping/hashes

by garbage777 (Acolyte)
on Jun 05, 2006 at 17:30 UTC ( [id://553656]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Need help from the esteemed monks on scoping/hashes
in thread Need help from the esteemed monks on scoping/hashes

Hi Dragonchild, As per your advice, I just rechecked that in the script at line 27 (below is the snippet of the script with line number), I am assigning each key, value pairs to a hash called "%mapping". Please see below -
24 if (/NAME_MAP/ .. /PORTS/) { 25 next if (/NAME_MAP/); 26 next if (/PORTS/); 27 %mapping = split; 28 @keys = sort keys %mapping; 29 foreach $k1 (sort keys %mapping) { 30 print "$k1 = $mapping{$k1}\n"; 31 } 32 }

However, it looks like in the next block of the code beginning at line "if (/D_NET/){...", the hash "%mapping" is not visible with in the "if(/D_NET/){..." block of the script. Please help as I am a total noobeee with Perl. Thank you very much for all the suggestions. Best Regards, Dan.

Replies are listed 'Best First'.
Re^5: Need help from the esteemed monks on scoping/hashes
by matze (Friar) on Jun 05, 2006 at 17:36 UTC
    With %mapping = split; you are overwriting your old mapping. You should use something like
    my ( $key, $value ) = split; $mapping{ $key } = $value if defined( $key ) and defined( $value );
    to preserve previous mappings.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553656]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found