in reply to Re: Re: Using a Sub to pull info. from a Text File
in thread Using a Sub to pull info. from a Text File

...open file... $linescore = 0; while(<DATA>) { if($linescore) { last if /^\s*$/; #break the loop if you find a ## blank line after a LINESCORE chomp; #clear off \n push @LS, $_; } elsif(/^LINESCORE/) { $linescore = 1 } } close DATA;
that puts linescore data into @LS, line by line, for you to work with at your leisure, you could split it and do more where the push is if you wanted...
                - Ant

Replies are listed 'Best First'.
(bbfu) (golf? or just TIMTOWTDI?) Re(4): Using a Sub to pull info. from a Text File
by bbfu (Curate) on Apr 11, 2001 at 00:57 UTC

    my @linescore; my @everything_else; while(<DATA>) { if(/^LINESCORE$/ .. /^\s*$/) { push @linescore, $_; } else { push @everything_else, $_; } }

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

Re: Re: Re: Re: Using a Sub to pull info. from a Text File
by rchiav (Deacon) on Apr 11, 2001 at 01:09 UTC
    Just to add to this, the other thing you could do instead of looking for a blank line, is to just read in the next two lines after linescore. Basically..

    my $ls = 0; while (<SCORES>) { if (/^LINESCORE/) { $ls++; } #linescore is greater than 1(we found LINESCORE) and less than 3(we +haven't read 2 lines yet) elsif ($ls && $ls < 3) { chomp; push @line, $_; $ls++ } }

    Hope this helps..
    Rich