Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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? }

In reply to Re^3: Need to skip two lines by linuxer
in thread Need to skip two lines by drodinthe559

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2018-11-21 05:30 GMT
    Find Nodes?
      Voting Booth?
      My code is most likely broken because:

      Results (237 votes). Check out past polls.