in reply to How to substitute 0 (zero) Instead of 'n/a'
One simple way is to force perl to treat $value like a number. Since it's the string "n/a", treating it like a number will evaluate to 0. To force perl to treat it like a number, do something numeric with it. For instance:
while (<FH> ) { chomp; if ( /Impressions:/ ) { my($text, $value) = split(/:/, $_); print "Impressions: $value"; print "\n" $value += 0; # turn $value into a number $impressions += $value; }
HOWEVER, you're already treating $value like a number when you add it to $impressions, so if you uncomment that line it should just work without the added step of adding 0 to $value
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to substitute 0 (zero) Instead of 'n/a'
by ysth (Canon) on Jan 22, 2004 at 19:36 UTC |