Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: multi-line parsing

by CountZero (Bishop)
on Mar 31, 2009 at 22:17 UTC ( #754555=note: print w/replies, xml ) Need Help??

in reply to multi-line parsing

Another solution, this one without any loops:
use strict; use warnings; my $data; { local $/ = undef; $data = <DATA>; } # my @results = $data =~ m/First Line\nSecond Line\n(\d+)\n/mg; # The m modifier was not really necessary here my @results = $data =~ m/First Line\nSecond Line\n(\d+)\n/g; print join "\n", @results; __DATA__ First Line Second Line 123 First Line Second Line 456 First Line Second Line 789 First Line Second Line 101112 First Line Second Line 131415
123 456 789 101112 131415


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2020-08-13 14:43 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (73 votes). Check out past polls.