Hello all,
I have a huge file (4.2GB) which contains entries similar to this:
Length_meas_C1C2 0.22
0.00 00.000 .090
Length_meas_C1C2 0.18
0.00 00.000 .090
0.00 00.000 .090
Length_meas_C1C2 0.18
Length_meas_C1C2 0.18
0.00 00.000 .090
Length_meas_C1C2 0.18
I am trying to parse this file and count the number of
times a certain layer number is found. Here is the
code I have...this works fine for smaller files, however
I am getting the out of memory error for the actual
data files. Can anyone offer any suggestions on how to
avoid this issue? Thanks in advance!
#!/opt/perl/5.8.7-32bit/bin/perl
my $inFile = $ARGV[0];
my %CALHASH;
my @CALARR;
if(!$ARGV[0]) {exit;}
open(FH, "<$inFile");
foreach $line (<FH>) {
chomp($line); #remove newline from end of line
if($line =~ /(\w+_meas_.*)/) {
##($layer, $enc) = split(' ', $1);
$layer = $1;
#print "$layer, $enc\n";
if (exists $CALHASH{$layer}) {
$CALHASH{$layer}{'freq'}++;
} else {
$CALHASH{$layer}{'freq'} = 1;
}
}
}
foreach $key (keys %CALHASH) {
print "$CALHASH{$key}{'freq'} $key\n";
}
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.