Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

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

That code doesn't do what you say it does. It searches through the file then prints the line after your target line, and every 3rd line after that till the end of the file. The reason is that the inner while loop continues until the file ends. Also the readline doesn't do what you mean for it to do, it actually reads a line from the file (<FILE>) then uses that as a argument to readline. If you had used warnings it would have complained about a readline on unopened filehandle. readline(FILE)is the same as <FILE> and is not restricted to a while loop so where ever you read that is wrong. Here is a way over commented piece of code that does what you say you want :)

use warnings; use strict; my $success = 0; open(FILE, "<", "dumptape.log") or die "Couldn't open dumptape.log: $!"; while (<FILE>) { if (/Dump phase number 3/) { # We found the line my $line = <FILE>; # read the next line print $line; # print the next line <FILE>; # Skip a line <FILE>; # Skip a line $line = <FILE>; # read the fourth line print $line; # print the fourth line $success = 1; # we found it last; # So we're done! } } close FILE; if (! $success) { print "Failed dump log\n"; }

In reply to Re: Extracting Text Lines by tedrek
in thread Extracting Text Lines by mikevanhoff

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2021-12-07 10:30 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (33 votes). Check out past polls.