AndrewMcHorney wrote: > > I have some perl code that was working and for the life of me I > cannot determine why it is is failing now. All I am trying to do is > to create and open a new file using a date time stamp in the > filename. Below is the code snippet for the open, It is returning an > invalid argument error. > > > ($Seconds,$Minutes,$Hours,$Day,$Month,$Year) = (localtime)[0,1,2,3,4,5]; > $Year = $Year + 1900; > > $Date = $Month."-".$Day."-".$Year.".".$Hours.":".$Minutes.":".$Seconds; > > $DuplicateFileName = ">Duplicate_File_List_".$Date; > print $DuplicateFileName."\n"; > > $OpenStatus = 1; > > open DUPLICATE_FILE_NAME, $DuplicateFileName or $OpenStatus = 0; > if ($OpenStatus == 0) > { > print "$!"; > print " "; > die "Unable to open duplicate file name file\n"; > }
That is not code that has ever worked, except maybe on a Unix platform. It is also non-idiomatic. The reason you are getting 'Invalid argument' is that you have colons in the file name. That is pone of the characters that Windows will not tolerate in its file names, and since you are using Eudora for Windows I assume you are programming for a Windows platform as well. Take a look at the program below, which will do what you need. HTH, Rob use strict; use warnings; my ($sec,$min,$hour,$day,$month,$year) = localtime; $month++; $year += 1900; my $filename = sprintf 'Duplicate_File_List_%02d-%02d-%04d.%02d:%02d:%02d', $month, $day, $year, $hour, $min, $sec; print "$filename\n"; open my $fh, '>', $filename or die "Unable to open '$filename': $!"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/