MySQL Forums
Forum List  »  Perl

<write format> records order error
Posted by: Trent Mo
Date: January 25, 2010 06:00PM

Hi, all
I start working with <format> to produce some report, all is nice however in final spool records are in other order, completely different then they were done in script. Total confuse , looks like a bug for me. I have series of <format> handls pointing to the same file, I also do <print> to the same file. I figured it out that I can solve this doing OPEN/CLOSE for each <write>, but probably it would be too much. I post my test script, expecting output file records be in order of $cc.
Appreciate you advice, I looked at reporting method too and might use them later, but for now I need to solve this problem to get good sleep. Really can't understand, what is behind this <write>, where data is actually written to >>outfile or some temp storage and then all synced at the end? Or iti could be because I use very same file '>>spool.dat' for all filehandles. Is there any COMMIT in Perl, or work with buffer. I'm new to Perl, really blown away how compact and powerful it is, but need more system knowledge. Any info appreciated, here is my code below:
Best to all
Trent P.S.
I'm testing this on WindowsXP with latest ActivePerl.

#!/usr/bin/perl
use strict;
use warnings;
my $cc="1";
unlink ('spool.dat');
open (OUT_LOG, '>>spool.dat');
open (OUT_HEADER, '>>spool.dat');
open (OUT_DETL, '>>spool.dat');
open (OUT_FOOT, '>>spool.dat');
open (OUT_BR, '>>spool.dat');

#=============================================================================================
format OUT_HEADER=
@<<<==== f0rmat HEADER HEADER HEADER Page : @<<<
$cc, $cc
.
format OUT_DETL=
@<<<======== f0ramt detail line =======================
$cc
.
format OUT_FOOT=
@<<<======== f0rmat ===========FOOTER
$cc
.
format OUT_BR=
@<<<========= fOrmat BREAK
$cc
.
#===============================================================================================
write OUT_HEADER; $cc++;

write OUT_DETL; $cc++;
write OUT_DETL; $cc++;
write OUT_DETL; $cc++;
write OUT_BR; $cc++;

print OUT_LOG "$cc ................print after 1st break \n"; $cc++;

write OUT_DETL; $cc++;
write OUT_DETL; $cc++;
write OUT_DETL; $cc++;
write OUT_BR; $cc++;
print OUT_LOG "$cc ...............print after 2nd break \n"; $cc++;

write OUT_FOOT; $cc++;

print "basta \n";

Options: ReplyQuote


Subject
Written By
Posted
<write format> records order error
January 25, 2010 06:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.