Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Search/format Across Multiple Lines

by GrandFather (Saint)
on Jul 23, 2014 at 04:24 UTC ( [id://1094721]=note: print w/replies, xml ) Need Help??


in reply to Search/format Across Multiple Lines

Build up the current line by concatenating new bits on to it until you reach a new line. When you reach a new line spit out the previous line, then set the current line string to the time code prefix for the new line:

use strict; use warnings; my $currLine; while (<DATA>) { next if ! /^\\ TC: +(\S+) (.+)/; my ($timecode, $tail) = ($1, $2); if ($tail !~ /^÷/) { $currLine .= $tail; next; } print "$currLine\n" if defined $currLine; $currLine = "\ TC: $timecode $tail"; } print $currLine if defined $currLine; __DATA__ \ TC: 16:12:48;28 ÷1426÷1426÷142D÷142D÷1470÷1470AND W \ TC: 16:12:49;08 HI \ TC: 16:12:49;11 LE \ TC: 16:12:49;14 OVER \ TC: 16:12:49;19 T \ TC: 16:12:49;21 HE L \ TC: 16:12:49;24 AS \ TC: 16:12:49;27 T 10 \ TC: 16:12:50;07 ÷1426÷1426÷142D÷142D÷1470÷1470YEARS \ TC: 16:12:50;17 W \ TC: 16:12:50;19 E' \ TC: 16:12:50;21 VE M \ TC: 16:12:50;25 AD \ TC: 16:12:50;27 E \ TC: 16:12:51;09 MAJ \ TC: 16:12:51;13 OR \ TC: 16:12:52;22 ÷1426÷1426÷142D÷142D÷1470÷1470INVESTMENTS

Prints:

TC: 16:12:48;28 ÷1426÷1426÷142D÷142D÷1470÷1470AND WHILE OVER THE LAS +T 10 TC: 16:12:50;07 ÷1426÷1426÷142D÷142D÷1470÷1470YEARS WE'VE MADE MAJOR TC: 16:12:52;22 ÷1426÷1426÷142D÷142D÷1470÷1470INVESTMENTS
Perl is the programming world's equivalent of English

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1094721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-19 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found