in reply to Need help from the esteemed monks on scoping/hashes

Uncomment 'use strict;', fix those errors, and your problem will be self-evident.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re: Need help from the esteemed monks on scoping/hashes

Replies are listed 'Best First'.
Re^2: Need help from the esteemed monks on scoping/hashes
by garbage777 (Acolyte) on Jun 05, 2006 at 17:08 UTC
    Hi Dragonchild,
    I uncommented "use strict;" and executed the script. It complained about -

    Global symbol "%mapping" requires explicit package name at ./t line 26 +. Global symbol "%mapping" requires explicit package name at ./t line 27 +. Global symbol "%mapping" requires explicit package name at ./t line 30 +. Global symbol "%mapping" requires explicit package name at ./t line 31 +. Global symbol "%mapping" requires explicit package name at ./t line 39 +. Execution of ./t aborted due to compilation errors.


    Therefore I added "our %mapping;" in the script right after the "while(<IHF>) {" line and saved the script into a file called "t.pl". Now I get -
    Use of uninitialized value in concatenation (.) or string at ./t.pl li +ne 40, <IHF> line 233.


    I checked line 40 in the script. That line is -
    print "$mapping{$n}\n";

    Any suggestions? Thank you very much in advance.
    Best Regards,
    Dan
      You're accessing $mapping{$anet[0]} - did you ever assign to that key? Doesn't look like it . . .

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        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.