Hello Monks,
I'm struggling with something that I think is pretty simple, but I haven't been able to work it out and I'm hoping you all can lend a hand.
I have a Tab Delimited file similar to the following:
10 alpha
30 bravo
60 charlie
100 delta
500 echo
600 foxtrot
4 golf
22 hotel
900 igloo
800 juliet
999 kilo
What I need to be able to do is count those values in the first column that meet certain criteria such as >600,>1000, etc. So, using the data above, if I wanted to count those values that are > 600, I want a total result of "3".
I am able to read the file and parse the data with the following code but the count that I am using doesn't give me the total "3". Rather, it outputs:
1
1
1
Again, I think I am just missing something basic here - so, any suggestions would be appreciated.
#!/usr/bin/perl
use warnings;
use strict;
#open and read, the file
my $file = shift @ARGV;
open (FILE1, "<", $file) or die "Can't open '$file': $!";
while (<FILE1>)
{
chomp $_;
my($perfNum,$alphaVal) = split("\t", $_);
#print "$perfNum\n";
my$gt600ms=0;
if($perfNum > 600)
{
$gt600ms++;
print "$gt600ms\n";
}
}
close (FILE1);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.