I've never written a line of perl before ... and I've only been lurking on
the list for three hours or so. But I've been presented some code which was
written for Unix and I'm trying to run on NT using ActiveState Perl. It
converts a flat file from the USGS to a format we can get into our SQL
database.
It's running right now -- and I'm hoping that it will generate an output
file -- however I see no indication that an output file is being generated
as the program loops (it's been running for three hours or so -- see the
connection?)
the very end of the program are these lines:
__END__
flat2rdb.pl sitelist.str.fo
flat2rdb.pl is the name of the perl code. When this is done running will it
generate a file called sitelist.str.fo ? Entire code at end of message.
TYIA
Rob Clayton
WRE-Data/Modeling
City of Austin
ps. I must apologize for the rtf email. wish that I could deactivate it;
but there are restrictions on that sort of thing here.
#! /usr/bin/perl5
# Program for Chris Herrington
# Convert flatout files to RDB files
# with the format:
# STAID DATES TIMES PARAMETER_CODE VALUE
#-----------------------------------------------------------
# This command caused program to choke on NT: RC <begin edit>
# Get the date
#chomp($DTAG = (`date '+%Y%m%d%H%M%S'`));
# Get flatfile filename from command line
#chomp($QWFLAT = $ARGV[0]);
# </end edit> Edited out Unix Commands by RC
#-----------------------------------------------------------
# If flatfile filename not on command line prompt for it
if($QWFLAT eq '')
{
print "Enter QW flatfile file name -> ";
chomp($QWFLAT = <STDIN>);
}
# Check to make sure file exists
if(! -r $QWFLAT)
{
print "The file \"$QWFLAT\" not found\?\n";
exit;
}
open(FLAT, "< $QWFLAT") or die "Can\'t open $QWFLAT file.\n";
while(<FLAT>)
{
# print "$parmcount\n";
$line = $_;
$parmcount='';
$COL=40;
$STAID = substr($_, 0,20);
$STAID=~(s/^\s*(.*?)\s*$/$1/);
$DATE = substr($_, 20,10);
$DATE=~(s/^\s*(.*?)\s*$/$1/);
$TIME = substr($_,30,10);
$TIME=~(s/^\s*(.*?)\s*$/$1/);
$VALUE = substr($_,40,10);
$VALUE=~(s/^\s*(.*?)\s*$/$1/);
$COL=($COL+10);
# $crap=<STDIN>;
print "# $STAID Station Number\n" if($OLDSTNUM != $STAID);
print "DATE\tTIME\tSTORET\tRESULT\n8D\t4s\t5s\t10n\n" if($OLDSTNUM !=
$STAID);
open(PARMS, "<${QWFLAT}.parnames") or die "Can\'t open
${QWFLAT}.parnames file.\n";
while(<PARMS>)
{
next if(/^STAID|^DATES|^TIMES/);
($PARM, $junk)=split(/\s+/);
print "$DATE\t$TIME\t$PARM\t$VALUE\n" if(($VALUE !=
-999999)and($VALUE ne ''));
while($VALUE ne '')
{
while(<PARMS>)
{
($PARM, $junk)=split(/\s+/);
last;
}
$VALUE = substr($line,$COL,10);
$VALUE=~(s/^\s*(.*?)\s*$/$1/);
print "$DATE\t$TIME\t$PARM\t$VALUE\n" if(($VALUE !=
-999999)and($VALUE ne ''));
$COL=($COL+10);
}
}
$OLDSTNUM = $STAID;
}
__END__
flat2rdb.pl sitelist.str.fo