Nyec wrote:
>
> How about this?
>
> # BEGIN EXAMPLE
> #STDERR = //Your syslog or log file//
> # You may want/need to set the STDERR/STDOUT if
> # this program is set as a cronjob depending on your system.
> # Be sure to test logging and error output.
>
> #Date formatting
> my ($day, $month, $year) = (localtime)[3,4,5];
> $month++;
> if ($month < 10) {
> $month =~ s/^/0/; # Keeps date format consistent(ddmmyyyy)
Or just use sprintf.
> }
> $year += 1900;
> my $date = join($day,$month,$year);
^^^^
The first argument to join() is the string to join the rest of the
arguments with. So if $day is '05' and $month is '11' and $year is
'2002' the value of $date will be '11052002' but the OP wants
'05112002'.
> my $oldfile = "dev.txt";
>
> if (-e $oldfile) {
> my $datefile = $oldfile;
> $datefile =~ s/^dev/dev$date/;
> rename $oldfile, $datefile; #Note-> Overwrites any existing file
Instead of using -e to determine if an error occured use the return
value of rename.
> if (!-e $datefile) {
> die "'$datefile' was not created: $!";
> }
> } else {
> die "Can not open '$oldfile': $!";
^^^^^^^^^^^^ ^^
Neither -e nor rename actually opens the file and $! won't be set if -e
fails.
> }
>
> __END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]