Okay...

Thanks for all your answers!

>From all, I combinded the perfext solution:

rename("test.txt", "test" . &heute() . ".txt");

sub heute {
return (localtime(time))[3] . (localtime(time))[4] . ((localtime(time))[5]
1900);
}

Thanks ;)

Andreas
-----Ursprüngliche Nachricht-----
Von: Sudarshan Raghavan [mailto:[EMAIL PROTECTED]] 
Gesendet: Samstag, 14. September 2002 15:21
An: Perl beginners
Betreff: Re: AW: Rename "File" to "File$date"

On Sat, 14 Sep 2002, Sudarshan Raghavan wrote:

> 
> #!/usr/local/bin/perl -w
> use strict;
> 
> # The -w flag on the shebang line is one way to enable warnings, you
> # can also do it by a use warnings; at the start of your code. 
> # Also note the use strict; The reason I am emphasising on this is
> # that this will point out some basic errors that will help you in 
> # your learning.
> 
> my ($day, $mon, $year) = (localtime)[3,4,5];
> # Type perldoc -f localtime on your prompt and read through the doc
> $mon++;
> $year += 1900;
> 
> while (<*.txt>) {
>     # This will loop through all *.txt files in your cwd.
>     # perldoc -f glob and perldoc File::Glob
> 
>     (my $new_name = $_) =~ s/\.txt$/sprintf("%d%02d%d.txt",$day,$mon,$year)/e;

My bad, the same sprintf for every file. You can move the sprint above the
loop like this.

my $date_str = sprintf("%d%02d%d",$day,$mon,$year);
while (<*.txt>) {
   (my $new_name = $_) =~ s/\.txt$/${date_str}.txt/;
   rename ($_, $new_name);
}

>     # This regex replaces the '.txt' part of your filename into 'ddmmyyyy.txt'
>     # form. perldoc perlretut, perldoc perlre, perldoc -f sprintf 
>     
>     rename ($_, $new_name);
>     # perldoc -f rename
> }
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to