Craig Cardimon <> wrote:
> I need to read a large text file line by line until a certain tag is
> found, say <TAG>. This tag will exist on a line by itself. Then I
> need read in all subsequent lines, appending them to each other,
> until the ending tag </TAG> is found, again on a line by itself.   
> 
> My logic, if you can call it that, looks like this:
> 
> TAGAREA: while(<IN>)
> {
> 
>       if(m/<TAG>/i .. m/<\/TAG>/i)
>       {
>               $tagarea = $tagarea . $_ ;
>       }
> 
>       next TAGAREA unless defined $tagarea;
> }
> 
> I also have a variety of other screen-out tests I perform on $tagarea.
> If that variable contains any no-no's, I move on to the next TAGAREA.
> 
> That's the theory, anyway. The logic isn't functioning. Where am I
> going wrong? 

Hard to say, because you don't provide enough information. This is why
it is recommended to provide a short, self contained, script, including
data where necessary, to illustrate your problem. Something that we can
just cut&paste and run. Indeed, it is quite often the case that the act
of producing such a script will reveal the solution.

For example, the following does what I expect, based on your description
of what your trying to do, and the documentation for the range operator:
----------------------------------------------------------------
use strict;
use warnings;

my @tagarea;
while (<DATA>) {
    if (/<TAG>/ .. /<\/TAG>/) {
        push @tagarea, $_;
    }
    elsif (@tagarea > 0) {
        shift @tagarea; pop @tagarea;
        local $" = "";
        print "Collected '@tagarea'\n";
        @tagarea = ();
    }
}

__DATA__
stuff
stuff
<TAG>
intererstingstuff
interestingstuff
</TAG>
stuff
<TAG>
</TAG>
stuff
<TAG>
moreinterestingstuff
moreinterestingstuff
moreinterestingstuff
</TAG>
stuff
----------------------------------------------------------------

If you had posted something like that, and explained how its output
differed from your expectations it would have made it easier to help.
Otherwise we are just guessing.

As an aside, your code example suggests that the data looks suspiciously
like HTML/XML, for which the canonical answer might be to use the
appropriate parser. But again, without knowing ...

HTH

-- 
Brian Raven 


=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the 
intended addressee(s). Unauthorised reproduction, disclosure, modification, 
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message do not 
necessarily reflect those of Atos Euronext Market Solutions.

L'information contenue dans cet e-mail est confidentielle et uniquement 
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. 
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail 
vous parvient par erreur, nous vous prions de bien vouloir prevenir 
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre 
systeme. Le contenu de ce message electronique ne represente pas necessairement 
la position ou le point de vue d'Atos Euronext Market Solutions.


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to