I have this code:
This code opens file and retrieves a value assigned to 'Impressions:' I would like to caunt all values. The output so far looks like this:#!c:\perl\bin\perl.exe use strict; use warnings FATAL => 'all'; use Fcntl qw[:flock]; my $impressions = 0; my $FH = 'C:\\scripts\\20040120\\mr\\imp\\'; chdir $FH or die "$!"; while (glob '*Jan2004*.txt') { open FH, $_ or die $!; flock FH, LOCK_SH or die $!; while (<FH> ) { chomp; if ( /Impressions:/ ) { my($text, $value) = split(/:/, $_); print "Impressions: $value"; print "\n" #$impressions += $value; } } close FH or die $!; } print 'Total impressions: ', $impressions or die $!;<br>
Because there are 'n/a' I cant count the impressions together. How should I change the script so it will replace any occurence of 'n/a' with 0 (zero)?C:\scripts\20040120\mr>perl c07_impressions_i.pl Impressions: 85 Impressions: 19298 Impressions: n/a Impressions: 25082 Impressions: 8314 Impressions: 8663 Impressions: 8672 Impressions: 8078 Impressions: n/a Impressions: 26167 Impressions: 7708 Impressions: 8247 Impressions: 14070 Impressions: 9641 Impressions: n/a Total impressions: 0 C:\scripts\20040120\mr>
Thank you for your time.
danield
update (broquaint): tidied up formatting
In reply to How to substitute 0 (zero) Instead of 'n/a' by danield
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |