in reply to N/A replacement not working

that looks suspicious to me... I'm thinking what you really wanted was:

$h[$i] = ($h[$i] eq 'N/A') ? 0 : $h[$i];
But having typed that just now I have a question as to what has been assigned to $i? Either your code snippet is woefully incomplete or ... ??? Did you use strict;?


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: N/A replacement not working
by baperl (Sexton) on Aug 10, 2011 at 15:29 UTC
    $i is an int. the print statement works fine as I've shown in the code snippet, and I have used strict. I'm not sure how your if-else is different from mine....nevertheless, I tried yours and it still returns N/A

      The difference is that his if-else actually does something to the data while your if-else is practically a no-op (i.e. it does nothing except testing the values)

      Are you sure that what you see as 'N/A' on the screen is not really "N/A\n" or ' N/A '? Also you test $h[$i], but print $h[1].

      The ($h[$i] eq 'N/A') ? 0 : $h[$i]; is working ok. The question is what do you want to do with this? As of now the result will be lost ... You need to save it into some var and act on it or print it.

      Which one of the prints returns the N/A? If it's the first one $h[0] = ($h[$i] eq 'N/A') ? 0 : $h[$i]; otherwise $h[1] = ($h[$i] eq 'N/A') ? 0 : $h[$i];

        thank you guys, I appreciate everyone's response and the clarification. Since I was not assigning it to the variable, it was giving the problem. it is fixed now :-)