in reply to Help With Perl and Files
$stamp=`/bin/date +%Y%m%d%H%M%S`; `/bin/touch /u01/scripts/logs/$stamp.tapes`;
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.$stamp=`/bin/date +%Y%m%d%H%M%S`; ... $file="/u01/scripts/logs/$stamp.tapes"; open( MYFILE, ">>$file");
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:
If you want to keep using back-ticks anyway, you'll need to figure out when it's appropriate/necessary to use "chomp".use POSIX; my $stamp = strftime( "%Y%m%d%H%M%S", localtime ); print ">>$stamp<<\n"; # look ma! no line-feed!
(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:
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./bin/cat 20070925133445 .tapes
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'
|
|---|