Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am currently processing a file that contains multiple companies and when complete I am manually splitting out based on Company name $f[0]. It would be a great timesaver if I could create a separate output file based on the Company name field $f[0]. Something like COMPANY-A.TXT, COMPANY-B.TXT, etc.

Thanks Perl Monks I appreciate your time and help

sample of company data: COMPANY-A, COMPANY-B, COMPANY-C, etc.
while (<$file>) { my @f = split '\s+', $_; # if ($f[0] =~ (/COMPANY-A/)) { # this is just for 1 company +and not efficient normally i remark this out if ( $f[0] =~ (/-C$/)) { # this process carryover records my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty +dates with previous month end my @ymd2 = split ',',$f[5] //= $prev_mth_end; my $diff = Delta_Days(@ymd1, @ymd2) +1; # total days my $prev = $prev_days{$f[2]} //= 0; my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0; # d +ays to be charged my $cost = ($amt) * 100; my $free = $diff - $amt; my $stg_chg = "N/A"; #static field my $sw_chg = "N/A"; #static filed my $waive = " "; my $cartot = ($cost + $stg_chg + $sw_chg); my $comment = "Carry over from last month"; my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s + %-12s %-12s %-12s %-8s %-12s %-40s\n"; 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; } #process non-carryover records else { my @ymd1 = split ',',$f[4] //= $prev_mth_end; # fill empty dat +es with previous month end my @ymd2 = split ',',$f[5] //= $prev_mth_end; my $diff = Delta_Days(@ymd1, @ymd2); my $prev = $prev_days{$f[2]} //= 0; my $amt = ($diff + $prev > 3) ? $diff + $prev - 3 : 0; my $cost = ($amt * 100); my $free = $diff - $amt; my $stg_chg = "N/A"; #static field my $sw_chg = "N/A"; #static field my $waive = ""; my $cartot = ($cost + $stg_chg + $sw_chg); my $comment = " "; my $pfmt = "%-12s %-5s %-8s %-5s %-15s %-15s %-6s %-6s %-8s %- +12s %-12s %-12s %-8s %-12s %-22s\n"; printf OUT $pfmt, @f[0..3], fmt_mdy($f[4]), fmt_mdy($f[5]), $d +iff, $free, $waive, fmt_curr($cost), $stg_chg, $sw_chg, $f[6], fmt_cu +rr($cartot), $comment; } # } }

In reply to create separate output files based on name by rruser

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [shmem]: welcome back, canary!

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2018-02-21 21:50 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (288 votes). Check out past polls.