D
deadpickle
I want the data to be saved to a text file in this format:
KGRI
KLNK
KHSI
And then reads into the program and then run through the match string.
I cant seem to get it to work correctly. Any help?
use strict;
use warnings;
$\ = "\n";
open ID, '<', 'stations.txt' or die "cannot open 'stations.txt' $!";
open TBL, 'stidtbl.txt' or die "cannot open 'stidtbl.txt' $!";
while ( my @tbl = <TBL> ) { #reads in a table of station IDs
my $idtbl = join ("|", @tbl);
chop ($idtbl);
print $idtbl;
while ( my $stations = <ID> ) { #finds the lat and long of a searched
station
next unless $stations =~ /\A.{20}($idtbl)\s+(.+)/;
my @id = split (" ",$2);
if (length($id[1]) == 5) {
chop ($id[3]);
chop ($id[5]);
my $p = ".";
my $lat = $id[2] . $p . $id[3];
my $long = $id[4] . $p . $id[5];
my @stid = ( $id[0], $lat, $long);
print "@stid";
}
else {
chop ($id[2]);
chop ($id[4]);
my $p = ".";
my $lat = $id[1] . $p . $id[2];
my $long = $id[3] . $p . $id[4];
my @stid = ( $id[0], $lat, $long);
print "@stid";
}
}
}
$idtbl keeps outputing:
KGRI
|KHSI
|KLNK
and I think it would work if it read in: KGRI|KHSI|KLNK
KGRI
KLNK
KHSI
And then reads into the program and then run through the match string.
I cant seem to get it to work correctly. Any help?
use strict;
use warnings;
$\ = "\n";
open ID, '<', 'stations.txt' or die "cannot open 'stations.txt' $!";
open TBL, 'stidtbl.txt' or die "cannot open 'stidtbl.txt' $!";
while ( my @tbl = <TBL> ) { #reads in a table of station IDs
my $idtbl = join ("|", @tbl);
chop ($idtbl);
print $idtbl;
while ( my $stations = <ID> ) { #finds the lat and long of a searched
station
next unless $stations =~ /\A.{20}($idtbl)\s+(.+)/;
my @id = split (" ",$2);
if (length($id[1]) == 5) {
chop ($id[3]);
chop ($id[5]);
my $p = ".";
my $lat = $id[2] . $p . $id[3];
my $long = $id[4] . $p . $id[5];
my @stid = ( $id[0], $lat, $long);
print "@stid";
}
else {
chop ($id[2]);
chop ($id[4]);
my $p = ".";
my $lat = $id[1] . $p . $id[2];
my $long = $id[3] . $p . $id[4];
my @stid = ( $id[0], $lat, $long);
print "@stid";
}
}
}
$idtbl keeps outputing:
KGRI
|KHSI
|KLNK
and I think it would work if it read in: KGRI|KHSI|KLNK