Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
laziness, impatience, and hubris
 
PerlMonks  

Re: Print a previous to previous of a matching line

by McA (Deacon)
on Oct 08, 2013 at 09:46 UTC ( #1057396=note: print w/ replies, xml ) Need Help??


in reply to Print a previous to previous of a matching line

Hi,

in this case I would take the following approach:

#!/usr/bin/env perl use strict; use warnings; use 5.010; # read first line assuming it is a kind of block seperator my $bsep = <>; $/ = $bsep; while(defined(my $block = <>)) { chomp $block; my @records = split /\n/, $block; next if @records < 3; # malformed block foreach my $record (@records) { say $record; } say "========================"; }

Now you can find and operate on every block how you like.

Best regards
McA


Comment on Re: Print a previous to previous of a matching line
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-04-17 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (440 votes), past polls