in reply to hash question

"print OUT ($naccess{$1}) if (exists($naccess{$1}));"

To make your code more robust, you better first check whether $1 is actually set, before you check whether it exists in the hash.

Replies are listed 'Best First'.
Re^2: hash question
by Anonymous Monk on Nov 21, 2004 at 21:50 UTC
    i know that the $1 is being called correctly. prints the values i want
      this is my code
      $first = shift@ARGV; $second = shift@ARGV; open (IN, "<$first"); open (IN2, "<$second"); open (OUT, ">NACCESS"); %naccess = map { /^\s+\S+\s+\S+\s+(\S+)/; ($1 => $_) } <IN2>; close (IN2); while (<IN>) { chomp; /^\s+(\S+)/; print OUT ($1) unless (exists($naccess{$1})); } close (IN);
      IN2 FILE
      1 59 49 0.0 0 100.0 0.0 1 60 50 0.0 0 100.0 0.0
      IN FILE
      112 104.35 141.94 115 22.34 29.13
        I echo ysth's comment. Maybe there's a problem opening one of the input files?
        open (IN, "<$first") or die("Can't open first input file: $!$/"); open (IN2, "<$second") or die("Can't open second input file: $!$/"); open (OUT, ">NACCESS") or die("Can't open output file: $!$/");
        Works for me, but you may want to print OUT "$1\n" unless ... instead.