Perl
by Bill Curran <bcurran(at)vision3.com>
|
Date: |
Mon, 10 Jan 2000 17:00:50 -0600 |
To: |
hwg-languages(at)hwg.org |
|
todo: View
Thread,
Original
|
|
I am writing a Perl script to open one document -- which contains multiple
lines -- match a list in that document, and then write that list to another
document. I am able to match only the last line in the document. Anybody
venture a guess as to why? Here is my code:
use strict;
print "Enter the name of the document (include extension): \n";
my $filename;
chomp ($filename = <STDIN>);
open (DATA, "$filename");
print "Enter the city of the opposing team: \n";
my ($city, @data1, @data2);
chomp ($city = <STDIN>);
while (<DATA>) {
my $home = 'Tennessee';
@data2 =
/($home)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)/;
@data1 =
/($city)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)(\s+?)(\d+?)/;
}
close DATA;
open (FILE, ">>newfile.html");
print FILE $data2[0];
close FILE;
Here is the file I am trying to read from:
This is the beginning of the document.
Cleveland 14 7 14 6 41
Tennessee 7 14 7 14 42
I am able to successfully match and write any of the elements in the last
line, but not elsewhere in the document.
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA