Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: regular expression

by jbt (Chaplain)
on Aug 16, 2009 at 13:55 UTC ( [id://789014]=note: print w/replies, xml ) Need Help??


in reply to Re: regular expression
in thread regular expression

Maybe something as simple as:

my $flag; while(<DATA>){ if (/^{(\w+)}/) { $flag = $1; } elsif ($flag =~ m/AUTHOR/) { # "store" values here } }

Replies are listed 'Best First'.
Re^3: regular expression
by Anonymous Monk on Aug 16, 2009 at 14:31 UTC
    The output should be
    By June Fletcher JOURNAL Richard White MacCUBBIN
    Line below the {AUTHOR} and start of another '{'

      My homework:

      my $flag = 0; while (<DATA>) { ($flag = ($1 eq "AUTHOR"), next) if /\{(\w+)\}/; print $_ if $flag; }

      No need to chomp... record terminator will be used in the output.

        Tou forgot to unset your flag
        #!/usr/bin/perl use strict; use warnings; my $flag=0; while(<DATA>){ if (/\{AUTHOR\}/){ $flag=1; next; } if (/^\{/){ $flag=0; next; } print $_ if $flag; } __DATA__ {TAG} tag1 {AUTHOR} By June Fletcher JOURNAL {TAG} tag2 TOM MacCUBBIN {DATA} data1 {AUTHOR} Richard White {AUTHOR} MacCUBBIN {SOUR}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-18 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found