Hello,

I have this code:

#!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>
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:\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>
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)?

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.