Dave Thacker wrote:
I'm reading from a database and attempting to write out to several different files using a defined format. I'm using this tutorial on formats as a reference. http://www.webreference.com/programming/perl/format/2.html

You should really read the documentation that comes with Perl instead:

perldoc perlform

When I run the script below, I get the error:
Can't find string terminator "" anywhere before EOF at ./roster-report.pl line 54.

I *think* I've get everything set up properly, and I'm not sure what I'm missing. The script is below. Please give me a pointer to the error.

TIA  Dave

#!/usr/bin/perl

use warnings;

use strict;

use DBI;
use Getopt::Long;
our ($opt_league, $opt_div);


&GetOptions("league=s", "div=s");

print "Working on the $opt_league league, division $opt_div\n";

#connect to database
my $dbh = DBI->connect("DBI:mysql:database=efl",
                      'user',
                      'password',
                      ) or die "Can't connect to database";

#set the root directory of the installation
my $rootdir= "/home/dthacker/efl/dev/";


#open teams.dir for reading
open( CLUB, "<$rootdir/teams.dir"  ) or die "Can't open teams.dir : $!";
while (<CLUB>) {
    print $_;
    my $roster_file=$_;
    my $club = substr($_, 0,3);

while ( my $roster_file = <CLUB> ) {
    print $roster_file;
    my $club = substr $roster_file, 0, 3;

    my $strsql = <<EOT;

select name, age, nat, st, tk, ps, sh, agg, kab, tab, pab, sab
from players where players.club="$club"
EOT

    my $sth = $dbh->prepare($strsql);


$sth->execute() or die "Couldn't execute statement: $DBI::errstr; stopped";

    my ($name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, $sab);
FORMAT RF =

Perl is case sensitive so that should be:

format RF =

      <<<<<<<<<<<<<<  << <<< << << << << << << <<< <<< <<< <<<

perldoc perlform
[ *snip* ]
    Picture lines contain output field definitions, intermingled with
    literal text. These lines do not undergo any kind of variable
    interpolation.  Field definitions are made up from a set of
    characters, for starting and extending a field to its desired width.
    This is the complete set of characters for field definitions:

       @    start of regular field
       ^    start of special field

You have to start your fields with one of these two characters (normally @).

      @<<<<<<<<<<<<<  @< @<< @< @< @< @< @< @< @<< @<< @<< @<<

      $name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, $sab
.

    open (RF, ">$roster_file");

You should *always* verify that the file opened correctly:

    open RF, '>', $roster_file or die "Cannot open '$roster_file' $!";

while ( my ($name, $age, $nat, $st, $tk, $ps, $sh, $agg, $kab, $tab, $pab, $sab) = $sth->fetchrow_array() ) {
        write RF;
    }

    close RF;

}
$dbh->disconnect();
close CLUB;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to