You could consider the following things:
- Don't use $_ as loop variable; use $source directly
- remove the parentheses in the regex (for skipping blank lines); you don't need to capture the whitespaces, do you?
- compare fixed strings directly (without regex); check Equality Operators for info about eq and ne
- I don't see a need for $sorter2; just leave it out.
- If all your ifs are alternatives, you can use if/elsif/elsif(/else) and leave out the next calls.
So this is, what I came up with:
# don't bother $_; use $source directly as loop variable
while ( my $source = <SOURCE> ) {
# skip blank lines; no need for capturing ()
next if $source =~ m/^\s*$/;
# compare fixed strings directly without regex; use operators eq o
+r ne
if ( substr( $source, 145, 16 ) eq 'Page: 1' ) {
$page1 = 1;
}
elsif ( substr( $source, 76, 11 ) eq 'Run Listing' ) {
$reporttype = 1;
}
elsif ( substr( $source, 72, 9 ) eq 'Sorter: 2' ) {
# no need for $sorter2; just check the other variables and do
+your stuff
if ( $page1 == 1 and $reporttype == 1 ) {
# just personal preference; post increment
$dcount++;
# personal preference; print a list instead of concatted s
+trings
print substr( $source, 83, 20 ), "\n";
$page1 = 0;
$reporttype = 0;
# leave out next, if there is no more code in the while-lo
+op
#next;
}
}
# no other stuff here?
}
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.