mantra2006 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I am struck up in a strange situation and got to be resolved asap...wondering where the problem is...
my $busnDate; my $valuFileName="ABCD_060824010101.DAT"; my $distFileName="EFGH_060824010101.DAT"; my $tranFileName="HIJK_060824010101.DAT"; my $tmp_file="C:\\temp\\testtmp.tmp"; $busnDate = substr($valuFileName, index($valuFileName, '_')+1, 12); print $busnDate; # store file names - order should be BUSINESS_DATE VALU DIST TRAN print "\nStoring file names in file $tmp_file: "; open(TMP_FILE, "> $tmp_file") or die "failed\n"; print "SUCCESS\n"; print TMP_FILE $valuFileName . "\n"; print TMP_FILE $distFileName . "\n"; print TMP_FILE $tranFileName . "\n"; print TMP_FILE $busnDate; close TMP_FILE;
The above code is suppose to write valu, dist, tran and timestamp
...but surprisingly only valu, dist, tran is written into file and not time
Can anybody tell me how to makesure it writes timestamp
its critical and thanks for the help

Sridhar

Replies are listed 'Best First'.
Re: Writing to a File
by davidrw (Prior) on Aug 25, 2006 at 12:45 UTC
    That code does work ... Perhaps you just missed the timestamp because there's no endline?
    [me@host me]$ cat C:\\temp\\testtmp.tmp ABCD_060824010101.DAT EFGH_060824010101.DAT HIJK_060824010101.DAT 060824010101[me@host me]$
    in the spirit of TMTOWTDI:
    my $valuFileName="ABCD_060824010101.DAT"; my $distFileName="EFGH_060824010101.DAT"; my $tranFileName="HIJK_060824010101.DAT"; my $tmp_file="/tmp/testtmp.tmp"; my ($busnDate) = $valuFileName =~ /_(\d{12})/; open(TMP_FILE, ">", $tmp_file) or die "failed to write '$tmp_file': + $!\n"; print TMP_FILE join("\n", $valuFileName, $distFileName, $tranFileNa +me, $busnDate); close TMP_FILE;
Re: Writing to a File
by holli (Abbot) on Aug 25, 2006 at 12:42 UTC
    Works for me. Output file is
    ABCD_060824010101.DAT EFGH_060824010101.DAT HIJK_060824010101.DAT 060824010101


    holli, /regexed monk/
Re: Writing to a File
by Velaki (Chaplain) on Aug 25, 2006 at 12:43 UTC

    I just ran the code, and it wrote the following into my test output file:

    ABCD_060824010101.DAT EFGH_060824010101.DAT HIJK_060824010101.DAT 060824010101

    What else have you tried?

    -v.

    "Perl. There is no substitute."
Re: Writing to a File
by imp (Priest) on Aug 25, 2006 at 12:43 UTC
    Ran the code on my WinXP machine using ActiveState perl 5.8.8 and it worked fine.

    When you are checking whether it worked are you opening c:\temp\testtmp.tmp in a text editor, or reading it with a perl script?

Re: Writing to a File
by mantra2006 (Hermit) on Aug 25, 2006 at 16:24 UTC
    Hello Monks

    Thanks to all the inputs...I added
    . "\n"
    and it printed the time..the reason for solution was it worked
    all the time without new line character program used to write all in tmp file and
    it started failing since this morning
    still not sure why this behaviour
    Thanks again for all the replies which gave me an
    opportunity to try all sorts of things and worked well in the end


    Sridhar
Re: Writing to a File
by mantra2006 (Hermit) on Aug 25, 2006 at 13:12 UTC
    The following is the output from scheduler and the content in tmp file
    found ABCD_060824010101.DAT found EFGH_060824010101.DAT found HIJK_060824010101.DAT Storing file names in file C:\\temp\\testtmp.tmp: SUCCESS Output from tmp ABCD118104505.DAT EFGH118104505.DAT HIJK118104505.DAT
    And time stamp is missing...
    Sridhar
      You've been asked several questions in the above responses. You might want to respond to those points if you expect the authors. How are you reading the file?
      It has been pointed out to you that the last print statement does not have a newline. Have you tried by changing the last print statement to:
      print TMP_FILE $busnDate ."\n";
      -rob
      print some static text before/after/near the timestamp so that you know *something* is getting printed there. Once you figure that out, look at how you are assigning the date - I know under cron in *nix, you do not operate under the same user environment you are used to, so it may be the same with this scheduler...not sure if it affects things, but it just might if you are relying on your interactive environemnt.
A reply falls below the community's threshold of quality. You may see it by logging in.