my %count=();  # A hash -it is bcos of of key/value pairs?

Yes, this declared a hash to store the results of counting the lines. The key will be one of either 'CLEAN','SPAM','INFECTED','BANNED','BAD_HEADER','REJECTED' and the value is the count.

while (<$fh>){

Read each line of the file into $_

  if (/amavis.*(Passed|Blocked) (CLEAN|SPAM|INFECTED|BANNED)/){

Match the line read (in $_) against the regex pattern like grep. The first word captured (Passed or Block) will be in $1 and the second (CLEAN or SPAM or INFECTED or BANNED) will be in $2

++$count{$2}; # Why ++$count? why {$2} here? is it bcos of (Passed +|Blocked) ?

For example, if $2 is the word CLEAN increment the hash $count{'CLEAN'}

} elsif (/amavis.*(BAD-HEADER)-/) { ++$count{$1}; # why {$1} here? is it bcos of (BAD-HEADER)

Yes, this regex has only 1 set of brackets so if it matches the word BAD-HEADER will be in $1

} elsif (/reject/){ ++$count{'REJECTED'}; #Hmm, Why {'REJECTED'}? } }

I chose REJECTED because 'rejected' was the label in your graph and all the other keys are upper case

my @data = map{ $count{$_} || 0 } qw(CLEAN SPAM INFECTED BANNED BAD-HEADER REJECTED);

map is a convenient way of creating an array from another another array. It is the same as

my @data=(); $data[0] = $count{'CLEAN'} || 0; # use 0 if $count{'CLEAN'} is undefin +ed $data[1] = $count{'SPAM'} || 0; $data[2] = $count{'INFECTED'} || 0; $data[3] = $count{'BANNED'} || 0; $data[4] = $count{'BAD-HEADER'} || 0; $data[5] = $count{'REJECTED'} || 0;
poj

In reply to Re^7: problem with show_values => 1, while drawing a bar graph with variables by poj
in thread problem with show_values => 1, while drawing a bar graph with variables by theravadamonk

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.