Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Extracting blocks of text

by Rhose (Priest)
on Jan 30, 2004 at 14:38 UTC ( #325239=note: print w/replies, xml ) Need Help??


in reply to Extracting blocks of text

You could also use the range (flip-flop) operator. The sample below will print lines from the line which starts with "head" (^ anchors to the start) to the one which ends with "tail" (\s*$ allows some white space after tail.)

#!/usr/bin/perl use strict; use warnings; while(<DATA>) { print if /^head/i../tail\s*$/i; } __DATA__ HEAD gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla tail gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus head bla bla gugus gugus tail bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus head bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus tail gugus gugus

Output

HEAD gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla tail gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus gugus bla bla gugus head bla bla gugus gugus tail

Update
If you have the camel book, you can find a discussion on this starting on page 90 (2nd Edition).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://325239]
help
Chatterbox?
[Lady_Aleena]: I don't hate it, it just drives me crazy.
[Discipulus]: LA the solution is portable to whatever
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation
[Discipulus]: and in the wanted sub you just calculate the duretion and add it the total, stop
[shmem]: sub wanted { push @files, $File::Find::name if $File::Find::name =~/\.mp3$/ }

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-04-23 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.