Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: create separate output files based on name

by Laurent_R (Prior)
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?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2015-04-02 10:15 GMT
Find Nodes?
    Voting Booth?

    Who makes your decisions?

    Results (63 votes), past polls