Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Regex to fix up records, some multiline fields, some not

by Athanasius (Prior)
on Aug 20, 2013 at 09:10 UTC ( #1050158=note: print w/ replies, xml ) Need Help??


in reply to Regex to fix up records, some multiline fields, some not

You need to add an /s modifier to the regex:

#! perl use strict; use warnings; our $/ = ''; while (my $currentrecord = <DATA>) { if ($currentrecord =~ m/^field2(.*)\nfield3/msi) { my $field2data = $1; print "Found \$field2data = $field2data\n"; } } __DATA__ record 1: field1: data 1 monday field2: data 2 monday field3: data 3 monday record 2: field1: data 1 tuesday field2: data 2 tuesday tuesday details line 1 tuesday details line 2 field3: data 3 tuesday

Output:

19:07 >perl 692_SoPW.pl Found $field2data = : data 2 monday Found $field2data = : data 2 tuesday tuesday details line 1 tuesday details line 2 19:08 >

See perlre#Modifiers.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Regex to fix up records, some multiline fields, some not
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (18)
As of 2014-07-11 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls