On Friday 13 September 2002 12:06 am, Kauffmann, Andreas wrote: > Hy everybody in the List! > > I have a Problem writing a little perl application... > > Im a very newbie to programming and need your help :) > > > The Problem is: > > I have a file "dev.txt" and I want to rename it once a day (with a cronjob) > like "dev13092002.txt" > > So i need to rename it with a date variable. > > All I have at the moment is: > > #!/usr/bin/perl > $d = `date`; > $d = /pattern1(pattern2)/; > sytem("cp test.txt test`$d`.txt"); > > > Does anyone of you know how to do that?
How about this? nyec # 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) } $year += 1900; my $date = join($day,$month,$year); my $oldfile = "dev.txt"; if (-e $oldfile) { my $datefile = $oldfile; $datefile =~ s/^dev/dev$date/; rename $oldfile, $datefile; #Note-> Overwrites any existing file if (!-e $datefile) { die "'$datefile' was not created: $!"; } } else { die "Can not open '$oldfile': $!"; } __END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]