CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
write with format: what is the order

 



trento
New User

Jan 24, 2010, 1:54 AM

Post #1 of 3 (624 views)
write with format: what is the order Can't Post

Hi, all
I have some formatted reports consisted of HEADER, DETAIL, SUB_TOTALS, GRAND_TOTALS lines.
In my file could be several breaks by key, so could be several groups of DETL+SUB_TOTALS groups and because of page breaks could be several number of HEADERs lines.

I just can not understand why I see my records in different order iin result file then they were executed in script, it appeared that they are in the order how I closed my files at the end of script.

For now I open all filehandles once and close them once at the end. All my <format > handles point to the same file with >>:

open (OUT_PRE, '>>spool.dat');
open (OUT_HEADER, '>>spool.dat');
open (OUT_DETL, '>>spool.dat');
open (OUT_GRANDTOTALS, '>>spool.dat');
open (OUT_SUBTOTALS, '>>spool.dat');

Anybody can tell me how I can make my records in the spool.dat be in the same order my <write> executed along the program, i.e
PPE
HEADER
DETL 1
DETL 2
DETL 3
SUBTOTALS
DETL 4
DETL5
SUBTOTALS
GRANDTOTALS

Do you think I need every time before <write> open/close file? But I might have 1K+ of them during my execution, it will be killer for files..

Appreciate you help, 2am in CA and I still trying to get how I can make it work.
BTW: I'm on last ActivePerl installed on my XP'Pro laptop if it matters.
my test script is attached

Thanks to all
Trent


(This post was edited by trento on Jan 24, 2010, 2:02 AM)
Attachments: pz.pl (1.28 KB)


FishMonger
Veteran / Moderator

Jan 24, 2010, 6:48 AM

Post #2 of 3 (617 views)
Re: [trento] write with format: what is the order [In reply to] Can't Post

We could fix what you currently have, but I think this would be a better approach.

http://search.cpan.org/~davidius/Text-Report-1.004/lib/Text/Report.pm


trento
New User

Jan 24, 2010, 11:06 AM

Post #3 of 3 (612 views)
Re: [FishMonger] write with format: what is the order [In reply to] Can't Post

Thanks, FishMonger for link, I saw already something simular :Reporter.

And still .. what is going on on the background if I do <write Header> where <format Header ...> which linked to >> spool.txt where this contents go: to file or some temp storage which accommodates all <writes> and them pastes them at the end.

My report is not big deal, I almost done with script with <format>, just need to fix this issue. Appreciate all opinions.

Best
Trent

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives