Greetings Monks,

I am trying to write a sequence of files out. I seem to have run into a problem, where all of the records end up in the same file. I am not sure why this is happening. Granted it is the first time I am trying to do something like this. As always your help is greatly appreciated.

I call the sub with two values; the first value is the first two digits of an account code. A sample account would look like: 01-B4 123456 and a tabbed record that I want written to a file that would look similar to: 1\t2\t20071107\t01-B4 123456\tPAID\t91.40

All the records appear in the file, it ‘s just they all end up in the same file. I was expecting the directory to look something like:
msg_beta_4250.txt
msg_beta_4450.txt
msg_beta_1240.txt

Any thoughts or recommendations on what I might look for to correct his behavior?

push(@passVars, $passCompCode); push(@passVars, $passLogRecord); write_msg_File(@passVars); sub write_msg_File { my $compCodeStr = $_[0]; my $logDataStr = $_[1]; my $logCompCode; $logCompCode = get_Comp_Code($compCodeStr); my $outFile = "/root/acs/out/msg_beta_" . "$logCompCode" . "\.txt"; #my $outFile = "/home/clr/log/msg" . "$logCompCode" . "\.txt"; open (WRECORD, ">> $outFile") or warn "Cannot Write Record! - $!"; print WRECORD $logDataStr; close (WRECORD); system "chown apache:apache $outFile"; system "chmod a=rw $outFile"; } #sub sub get_Comp_Code { my $companyRef = $_[0]; $companyRef =~ s/^0*//; my @companyArray = ("0000","4250","4450","3943","3943","4095","4241 +","1240","3943","4250","3943","1850","1850","4450","4450","1900","185 +5","1855","1855","1855","1863","1872","1855","1865","1855","1870","18 +55","3436","0000","1389","1780","0000","1872","3943","1864","3438","0 +000","1864","1864","1864","1240","1240","1240","1551","1392","1392"," +0000","1391","1451","0000","1397","4450"); if (($companyRef >= 52) || ($companyRef <= -1)) { return "0000"; } # if my $companyCode = $companyArray[$companyRef]; return $companyCode; } #sub
Update, bad copy and paste.
Before perlmonks.org: perl -e "print scalar(localtime);" After perlmonks.org : perl -e "use strict; use warnings; print scalar(localtime).\"\n\";"

In reply to How to write a sequence of files? by kensaigm

Title:
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, details, 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, summary, 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.