AHHH! My apologies!!! I wasn't aware it'd be a problem.
Another problem is that you're top-posting. Please stop that. Trim
your quoted material down to the smallest relevant bits, and
intersperce your comments as appropriate.
OK, well the script now writes to the spreadsheet, but it will only
write one line. I am reading in data from a text file and need the
script to write one line to the spreadsheet per line in the text file
based on information in a database. Here is the code:
#open file
$filename = shift;
Are you using strict and warnings? If not, please start. They catch
99% of the errors programmers make.
open(GR,"$filename") or die("Unable to open file");
1) Do not double-quote variables without reason. See also: perldoc -q
quoting
2) Use lexical filehandles, not global barewords (they are subject to
strict, they're not global, and they auto-close when they go out of
scope)
3) Use the three-argument form of open
4) State the *reason* the open failed if it does:
open my $GR, '<', $filename or die "Cannot open file: $!";
@sub =<GR>;
close(GR);
#FOR EACH RECORD IN TEXT FILE...
foreach $record (@sub)
There is absolutely no reason to read in the entire file into memory
and keep it there for the duration of this loop. Instead, read one
line at a time. At each iteration, discard the previously read line
and read the next:
while (my $record = said:
chop() is almost entirely a holdover from Perl 4. The new standard
idiom is chomp(). (What would happen if your text file happened to not
end with a newline?)
chomp $record;
$sub = uc($record);
$sql = "query";
$sth= $alloc_dbh->prepare($sql_psc_rachel);
Where did any of these variables come from?
$sth->execute();
while (($masterNum, $subNum, $platform, $machine,
$lastAlloc, $lastAllocDate, $chargeID,
$lastname, $balance) = $sth->fetchrow())
{
print OUT ("PSC Data: $masterNum, $subNum,
$platform, $machine, $lastAlloc, $lastAllocDate,
$chargeID, $lastname, $balance\n");
When did the OUT filehandle get declared?
#TGCDB info
%tgdata=getTGData();
$start = $tgdata{"$chargeID $platform
AllocData"};
$alloc = $tgdata{"$chargeID $platform
Alloc"};
$remaining = $tgdata{"$chargeID
$platform Remaining"};
print OUT ("data: $chargeID, Start
$start, Alloc $alloc, Remaining
$remaining\n");
my $row = 1;
Here you declare a brand new variable, within this loop. It does not
exist before this line, nor after this iteration of the loop ends.
$worksheet1->write($row, 0,
$masterNum);
Here (and for 10 more nearly identical lines), you use the $row
variable that you just declared.
Here you increment this variable...
.... but here, that variable goes out of scope. The next time through
the loop, a new $row is declared and initialized to 1. No piece of
code ever uses $row when it is any value other than 1.
Move your declaration of $row outside the loop.
Paul Lalli