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}