Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You often need to do something to a line depending on what is on the next line. One way to go is to store a line, move to the next line, decide what to do and then store the current line as appropriate.
#! /usr/perl/bin use warnings; use strict; my $skip = 0; my $last_line = <DATA>; chomp($last_line); while (my $current_line = <DATA>){ chomp($current_line); if ($current_line =~ /^\d{4}-\d{2}-\d{2}/){ if (not $skip){ print $last_line, qq{\n}; } else{ $skip = 0; } $last_line = $current_line; } else{ print $last_line, qq{ }, $current_line, qq{\n}; $skip = 1; } } print $last_line, qq{\n}; __DATA__ 2013-01-01 user1 user2 chat chat 2013-01-02 user3 user4 more chat more chat 2013-01-03 user5 user6 nazi nazi chat chat nazi 2013-01-04 user 7 user8 see you in the pub
2013-01-01 user1 user2 chat chat 2013-01-02 user3 user4 more chat more chat 2013-01-03 user5 user6 nazi nazi chat chat nazi 2013-01-04 user 7 user8 see you in the pub
Boy, am I rusty. It hurt my head getting that to compile and run. :-)

Updated: Reset the $skip flag.


In reply to Re: Parse chat & File::find by wfsp
in thread Parse chat & File::find by 4perl

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found