garbage777 has asked for the wisdom of the Perl Monks concerning the following question:
*NAME_MAP *1 ab *2 abc *3 abcd *4 def *5 ghi *6 klm *7 mno *8 kji *9 ips *10 dlm *PORTS *D_NET *2 25 *D_NET *3 16 *D_NET *5 8 *D_NET *9 3
When I execute this code I get the following error -#!/usr/bin/perl #use strict; use warnings; open(IHF, "<", "top.spef"); while( <IHF> ) { my @keys; my ($n, $k1); my %nets; my @net; my $item; next if (/^\n/); s/\*//g; s/^\s//g; s/\//:/g; ### Here we store the lines between the lines ### NAME_MAP and PORT into a hash called %mapping" ### and print the key,value pairs if (/NAME_MAP/ .. /PORTS/) { next if (/NAME_MAP/); next if (/PORTS/); %mapping = split; @keys = sort keys %mapping; foreach $k1 (sort keys %mapping) { print "$k1 = $mapping{$k1}\n"; } } if (/D_NET/) { my @anet = split; %nets = ($anet[1] , $anet[0]); for $n (sort keys %nets) { print "$mapping{$n}\n"; } } }
Use of uninitialized value in concatenation (.) or string at ./mapping +.pl line 39, <IHF> line 23
Can you kindly suggest me what I am doing wrong and how to fix this problem ? I very much appreciate all your help in advance.if (/D_NET/) { my @anet = split; %nets = ($anet[1] , $anet[0]); for $n (sort keys %nets) { print "$mapping{$n}\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help from the esteemed monks on scoping/hashes
by dragonchild (Archbishop) on Jun 05, 2006 at 16:58 UTC | |
by garbage777 (Acolyte) on Jun 05, 2006 at 17:08 UTC | |
by dragonchild (Archbishop) on Jun 05, 2006 at 17:18 UTC | |
by garbage777 (Acolyte) on Jun 05, 2006 at 17:30 UTC | |
by matze (Friar) on Jun 05, 2006 at 17:36 UTC | |
Re: Need help from the esteemed monks on scoping/hashes
by jwkrahn (Abbot) on Jun 05, 2006 at 21:39 UTC | |
Re: Need help from the esteemed monks on scoping/hashes
by ioannis (Abbot) on Jun 05, 2006 at 20:50 UTC |