On Fri, 13 Sep 2002, Kauffmann, Andreas wrote:

> Sorry for bugging you again, but you need to say me the whole script fort he 
>renaming process :(
> 
> I really have no clue about programming :( Ist not logical for me...

I think you should start reading through learning perl 3'rd edition for a 
good introduction to perl. As for your script here it is

#!/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;
    # 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
}

> 
> > 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
> 
> Enable warnings and use strict, will save you a lot of
> debugging time.
> 
> > $d = `date`;
> 
> Read through perldoc -f localtime
> 
> my ($day, $month, $year) = (localtime)[3,4,5];
> $month++;
> $year += 1900;
> 
> 
> > $d = /pattern1(pattern2)/;
> > sytem("cp test.txt test`$d`.txt");
> 
> Why are you copying when you actually want to rename the file.
> perldoc -f rename


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

Reply via email to