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

17|Cincinnati Reds 1|5746|Pokey Reese|2B|3|1|1|1|1|0|0|.343|.408|.429 2|5930|Sean Casey|1B|3|0|1|0|1|1|0|.200|.344|.320 3|4305|Ken Griffey Jr.|CF|4|1|2|2|5|0|1|.210|.326|.448 4|5699|Dmitri Young|LF|4|0|1|0|1|0|1|.287|.339|.446 4|5540|Alex Ochoa|LF|0|0|0|0|0|0|0|.297|.357|.595 5|4615|Eddie Taubensee|C|4|0|0|0|0|0|1|.325|.387|.542 6|4159|Dante Bichette|RF|3|0|2|0|2|0|0|.219|.265|.324 6|6174|Scott Williamson|P|0|0|0|0|0|0|0|-|-|- 7|5838|Aaron Boone|3B|3|0|0|0|0|0|0|.270|.389|.438 8|5508|Juan Castro|SS|3|1|1|0|2|0|0|.333|.333|.667 9|5346|Ron Villone|P|1|0|0|0|0|0|0|.222|.222|.222 9|5299|Michael Tucker|RF|0|0|0|0|0|0|0|.167|.375|.500 TOTALS|28|3|8|3|12|1|3 LINESCORE 24|St. Louis Cardinals|2|7|0|8|0|0|0|2|0|0|0|0|0 17|Cincinnati Reds|3|8|0|5|1|0|0|0|1|1|0|0|x DOUBLES 5046|Craig Paquette|24|St. Louis Cardinals|1|5 5508|Juan Castro|17|Cincinnati Reds|1|1
What I am trying to do is to pull the LINESCORE out and place it in a table at the top of my web page. Leaving all of the other data in its own table. Because write now, I have it set up where it just pulls everything in order.

Replies are listed 'Best First'.
Re:{3} Using a Sub to pull info. from a Text File
by jeroenes (Priest) on Apr 11, 2001 at 17:40 UTC
    Hey, this warrants a legimate use of supersplit! (first use of the third dimension I have encountered)
    use SuperSplit; $a = supersplit( '|',"\n","\n\n", $data_in_one_string); print $a->[0][1][2]; #will print 'Pokey Reese'
    Jeroen
    "We are not alone"(FZ)
Re: Re: Re: Using a Sub to pull info. from a Text File
by suaveant (Parson) on Apr 11, 2001 at 00:44 UTC
    ...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

      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.

      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

Re: Re: Re: Using a Sub to pull info. from a Text File
by Rhandom (Curate) on Apr 11, 2001 at 00:49 UTC
    How about...
    use IO::File (); my $fh = IO::File->new($filename,'r'); ### slurp it in my $txt; read($fh,$txt,-s $filename); my $LS = ($txt=~s/^(LINESCORE(.+?)\n\r?\n)//s) ? $1 : '';
    And now you have it. The other way is to read the file a line at a time and using sentinels funnel the information into two different variables.