Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm new so i'm sorry if this is a dumb question. I'm trying to fetch the data from http://vspx27.stanford.edu/teamstats/team32.txt but the info at the top is useless. I'm using LWP:Simple to get the data but don't know how to get rid of the top part.
FOLDING@HOME TEAM STATS: Team # 32 Tue Feb 28 14:59:59 PST 2006 team teamname score wu 32 www.overclockers.com 191314519 2819525 Team rank: 3 Team members: rank team rank name credit total team
is what i need to get rid of. I've looked into read() and some other things but nothing seems to work. Any ideas would be greatly appreciated. Thanks.

Replies are listed 'Best First'.
Re: i need to exclude data fetched from a .txt file
by atcroft (Abbot) on Mar 01, 2006 at 03:24 UTC

    Since you know that the header is the top 11 lines (lines 0 .. 10), then you could do something like this (a simple script to display the desired lines, which just loops thru the lines starting with the 12th line):

    #!/usr/bin/perl -w use strict; use LWP::Simple; my $stats_url = q{http://vspx27.stanford.edu/teamstats/team32.txt}; my $stats_txt = get($stats_url); my @lines = split(/\n/, $stats_txt); foreach my $i (11 .. $#lines) { print $lines[$i], qq{\n}; my @line_parts = split(/\s+/, $lines[$i]); # do something with the parts here, if desired.... }

    Another way, if you're looping thru a text file, is to look at the value of $., which contains the current line number of the last file handle accessed, and just use something like next if ($. < 11); in your loop as you read thru the file. Example:

    #!/usr/bin/perl -w use strict; my $data_file = qq{team32.txt}; open(DF, $data_file) or die(qq{Can't open $data_file for input: $!\n}); while (<DF>) { next if ($. < 11); chomp; print $_, qq{\n}; my @line_parts = split(/\s+/); # do something with the parts here, if desired.... } close(DF);

    Hope that helps.

Re: i need to exclude data fetched from a .txt file
by roboticus (Chancellor) on Mar 02, 2006 at 13:11 UTC
    Since it appears that the data sections each have headers and an easily recognizeable format, you could parse it something like this....
    #!/usr/bin/perl -w use strict; my $sect=0; # Not in a section yet while (<>) { if ($sect==1) { if (/(\d+)\s+(.+)\s+(\d+)\s+(\d+)\s*$/) { # Correct section AND format, assumed valid print "Sec1: $1, $2, $3, $4\n"; } else { $sect=0; # Wrong fmt, end of sect assumed } } elsif ($sect==2) { if (/(\d+)\s+(\d+)\s+(.*)\s+(\d+)\s+(\d+)\s+(\d+)\s*/) { print "Sec2: $1, $2, $3, $4, $5, $6\n"; } else { $sect=0; } } elsif (/^team\s+teamname\s+score\s+wu$/) { # Start of team info section $sect=1; } elsif (/^rank\s+team rank\s+name\s+credit\s+total\s+team$/) { # Start of rank info section $sect=2; } else { # Uninteresting line, ignore it... } }
    --roboticus