Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Print a previous to previous of a matching line

by McA (Priest)
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 having an uproarious good time at the Monastery: (9)
As of 2015-07-29 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls