in reply to Searching for Certain Values
That is, break up the line on spaces, assign each of the columns to variables, then print something if the data matches a test. Since your data is very regular, the code doesn't have to be complicated. You can make some modifications for simplicity:# Open the file containing data or abort with error message open(my $fh, "<", "some_file.txt") || die "Can't open file: $!"; # Run through all lines of the file, one by one while(my $line = <$fh>) { # Break up the line on whitespace, assign columns to vars my( $score,$scorePoints, $time,$timePoints, $record,$recordPoints, $size,$sizePoints, $age,$agePoints, $diff,$diffPoints, $size2,$size2Points, $name ) = split(/\s+/,$line,13); # Check to see if name matches if($name =~ /(intrepid|triumph)/) { print "$name\n", "Time: $timePoints, Difficulty: $diffPoints\n\n"; } }
Or to eliminate possibly-bogus data:# Assign only the columns you're interested in my ($timePoints,$diffPoints,$name) = +(split(/\s+/,$line,13))[3,11,1 +4];
Or for speed (don't bother splitting lines unless they have intrepid/triumph on them somewhere):# Ensure the line consists of 12 integers + something my ( ... ) = ($line =~ /^\s*(?:(\d+)\s*){12}(.*)/);
next unless $line =~ /(intrepid|triumph)/; my ( ... ) = ...; print ....;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching for Certain Values
by ikegami (Patriarch) on Jul 30, 2007 at 19:02 UTC | |
|
Re^2: Searching for Certain Values
by Anonymous Monk on Jul 30, 2007 at 18:14 UTC | |
by Dr.Avocado (Novice) on Jul 30, 2007 at 18:16 UTC | |
by ikegami (Patriarch) on Jul 30, 2007 at 19:00 UTC |