Hi Monks! It's been awhile.... My goal is to read records from a database and generate roster files based on the content of the field "club". I'm attempting to use format to specify where the fields should go and to print a 2 line header at the top of each file. My header is only showing up on the first file, the other files that are written only have records. Can you show me the error of my ways? My code, the input file, and samples of the output files are below. Thanks in advance!
#!/usr/bin/perl use strict; use warnings; 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", 'auser', 'apass', ) 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); my $strsql = <<EOT; select name, age, nat, st, tk, ps, sh, agg 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); format RF = @<<<<<<<<<<< @< @<< @< @< @< @< @< $name, $age, $nat, $st, $tk, $ps, $sh, $agg . format RF_TOP = Name Age Nat St Tk Ps Sh Ag KAb TAb PAb SAb Gam Sav Ktk Kps Sh +t Gls Ass DP Inj Sus ---------------------------------------------------------------------- +--------------------- . open (RF, ">$roster_file") or die "Can't open roster file $roster_ +file"; while ( ($name, $age, $nat, $st, $tk, $ps, $sh, $agg ) = $sth->fe +tchrow_array() ) { write RF; } close RF; } $dbh->disconnect(); --format of teams.dir-- dthacker@fluffy:~/efl/dev$ more teams.dir acm.txt bar.txt cel.txt dep.txt int.txt lyo.txt por.txt ran.txt rea.txt val.txt ----end of teams.dir----- ---start of acm.txt (first file produced)---- Name Age Nat St Tk Ps Sh Ag KAb TAb PAb SAb Gam Sav Ktk Kps Sh +t Gls Ass DP Inj Sus ---------------------------------------------------------------------- +--------------------- P_Pipolo 23 ita 12 1 1 1 22 F_Bikmaz 20 tur 8 1 1 1 16 O_Veigneau 23 fra 1 11 6 1 37 ----start of bar.txt (second file produced) I_Akinfeev 24 rus 11 1 1 1 25 C_Dinganga 21 cod 8 1 1 1 22 G_Bartolucci 27 ita 1 13 7 1 23 M_Licka 27 cze 1 11 9 1 20 D_Traore 32 fra 1 9 4 2 30

Dave
Code On!

In reply to format Header only prints on first of several files by dthacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.