Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: create separate output files based on name

by Laurent_R (Vicar)
on Dec 18, 2013 at 22:26 UTC ( #1067733=note: print w/ replies, xml ) Need Help??


in reply to create separate output files based on name

OK, assuming you have sorted your records by company, you can have something like this:

my $company = "unlikelyname"; my $OUT; while (<$file>) { my @f = split '\s+', $_; if ($f[0] !~ /$company/) { close $OUT if defined $OUT; open $OUT, ">", "$f[0].txt" or die "blabla $!"; $company = $f[0]; } my @ymd1 = split ',',$f[4] //= $prev_mth_end; my @ymd2 = split ',',$f[5] //= $prev_mth_end; # ... printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $diff +, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt_curr( +$cartot), $comment; }
I don't have data and can't test in detail, there may be some errors here and there, but I am fairly sure the basic idea works and it is very simple: you change company? Just close the previous file, open a new file with the same filehandler but a new name, so that you can always write to $OUT (and nonetheless to the right file), which will be at any time associated with the right file.


Comment on Re: create separate output files based on name
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067733]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-07-28 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls