I'm reading in a 500MB File with Sysread
Every line of this file has 31 fields separated with a Vertical Bar (|)
I'm interested in only a few of the 31 fields and I just cannot figure out the correct syntax for this. I've tried (.+?) 31 times, but that slows the program down so much, that it's not even funny.
Can someone please help? I suspect that I just need a very easy way to use split with this instead of a regex.
Line Example:
s0864|2003/04/14 00:00:41.136|MWP6|SeFraleidssV2
| 0.038|0000| |OH| |10.1.2.3 |807D|10183312 |10
+18331
2| | |20| |PR84|P2AP|B01P|NNN|C21209 | | | |
+ |00473
63|1419680| |A|ABCD
Here's the code that I've been trying to get to work.
$totalsentrycalls=0;
keys %count_by_sentry_server = 10;
keys %count_by_ip = 10000;
keys %count_by_api = 500;
keys %count_by_api_exec = 500;
while (sysread(INFILE, $buffer,16384,length $buffer)) {
while ($buffer =~ m/(.+?)\|(.*)\n/g) {
$totalsentrycalls++;
$count_by_sentry_server{$0}++;
$count_by_ip{$9}++;
$count_by_api{$3}++;
$count_by_api_exec{$3}{$totalsentrycalls}=$4;
if ($31 =~ /^[A-Z]+/) {
$hosts{$17}{$31}{$18}++;
} else {
if ($18 =~ /^[A-Z]+/) {
$hosts{$17}{AORDIRECT}{$18}++;
}
else {
$hosts{$17}{DB2}{LOCAL}++;
}
}
}
$buffer=substr($buffer, rindex($buffer, "\n"));
print "$totalsentrycalls\n";
}
Thanks!
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.