Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
pretty much I want to use flags in a loop and tell the program once you reach lets say C print it and then the line after that until point G I had was not automated and what I need is to automate it. I will let you see the code its my first time ever to use perl so it might look bad but what ever.
#!/\\perl # use strict; use warnings; use CQPerlExt; use Getopt::Long; use Time::Local; use File::Basename; # Put the file name in a string variable # so we can use it both to open the file # and to refer to in an error message # if needed. my( $dataLine ); my( $fileName ); my( $success ); # Hard-code the name of the file we're going to read. # This is the script itself. $fileName = '/\\rat09awp\ccscripts\Islam\test.log'; my $start = 0; # Attempt to open the file. We create a file handle called "IN". # Open returns a true value if it succeeded, an undefined # value if it didn't succeed. $success = open( IN, "<$fileName" ); if ( $success ) { # We opened the file successfully. # We loop until we don't get any more data from the file. Wh +en the # file has been exhausted, the value of $dataLine is set to +undefined. # So we simply test $dataLine to see if it is defined after +we have # obtained another line from the file. while ( defined( $dataLine = <IN> ) ) { # while (<IN>) { # print $_; # if ($_ =~ /Duplicate remedy_id:/) { if ($dataLine =~ /Duplicate remedy_id:/ ) { printf $dataLine; while($dataLine = <IN>) { if($dataLine =~ /Duplicate ip_address:/) { printf $dataLine; last; } else { printf $dataLine; } } } } # We have read all the lines from the file. # Close the file. close( IN ); } else { # Opening failed. The error message is stored in a special P +erl # variable, $!. The die() function prints an error message, +then # causes Perl to quit. die( "Can't open file '$fileName' for reading: $!.\n" ); }
Thanks

In reply to Re^10: Extract lines between two patterns by Anonymous Monk
in thread Extract lines between two patterns by mnithink

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-07-26 02:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (175 votes), past polls