I'm surprised (shocked... SHOCKED!) that others didn't mention it yet, but every time you do this:
$stamp=`/bin/date +%Y%m%d%H%M%S`; `/bin/touch /u01/scripts/logs/$stamp.tapes`;
(update: sorry... I mean every time you do this:)
$stamp=`/bin/date +%Y%m%d%H%M%S`; ... $file="/u01/scripts/logs/$stamp.tapes"; open( MYFILE, ">>$file");
you are creating a file in "/u01/scripts/logs/" that contains a line-feed character in the file name (between the last digit and the ".tapes"), because the return value from the first back-tick command includes the "\n" at the end of the output from /bin/date.

I don't know about you, but personally I hate it when I discover files that contain a line-feed in the middle of the file name. Crap like that can really ruin your day. I like using the POSIX module for getting date/time strings:

use POSIX; my $stamp = strftime( "%Y%m%d%H%M%S", localtime ); print ">>$stamp<<\n"; # look ma! no line-feed!
If you want to keep using back-ticks anyway, you'll need to figure out when it's appropriate/necessary to use "chomp".

(update:) ... Ooops -- I was forgetting an important detail about how back-tick strings work in perl. Whenever you use that $file name (with the line-feed in it) in a back-tick command, you are actually running TWO shell commands, like this:

/bin/cat 20070925133445 .tapes
Well, if there is ever an executable file called ".tapes" in you PATH, you'll have a wonderful time figuring out what really happened and why it happened.

Last update: It's not the sort of thing I like to experiment with but here's a harmless proof-of-concept -- check the difference between these two one-liners:

perl -e '$_ = `echo foo echo bar`; print' perl -e '$_ = `echo foo\necho bar`; print'

In reply to Re: Help With Perl and Files by graff
in thread Help With Perl and Files by mrbbq

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.