Perl Scripting problem - please help!


M

Mark

Hello,

I am new to PERL and I want to do a simple function (in LINUX):

find all files that have the extension pseudo.pdf and put the file
names in a file;
parse the file and change all file names current filename plus date:

pseudo+date+.pdf

Move the new file to pseudo directory :

I have written the code which seems to work without any errors and has
been accepted by PERL:

#!/usr/bin/perl -w
open (pdfs, "/var/www/html/reports/shops/pdflist.txt")
||Error('open','file');
@fnames=<pdfs>;
close (pdfs);
($second,$minute,$hour,$day,$month,$year,$weekday,$dayofyear,$isdst)=localtime(time);
$cmonth=$month+1;
$cyear=($year % 100);
$fdate=$cmonth.'-'.$day.'-'.$cyear;
$ext='.pdf';
foreach $pdffile (@fnames2) {
$pdffile=$pdffile.$fdate.$ext;
}
$n=1;
foreach $fnames (@fnames) {
$cnt=index($fnames,".pdf");
$newfile=substr($fnames,0,$cnt);
$newpdf=$newfile.$fdate.$ext;
print "fnames: $fnames \n";
print "new file: $newfile \n";
print "newpdf: $newpdf \n";
print "old= /var/www/html/reports/shops/$fnames \n";
print "new= /var/www/html/reports/shops/$newfile/$newpdf \n";
rename("/var/www/html/reports/shops/$fnames","/var/www/html/reports/shops/
$newfile/$newpdf");
print "\n";

}


I cannot get the rename function to work even if I use the same
directory. I don't get any errors and the file permissions are set
correctly on the files.

Anyone know why this does not work?

Thanks,

Mark
(e-mail address removed)
 
Ad

Advertisements

F

Felix Geerinckx

...
rename("/var/www/html/reports/shops/$fnames","/var/www/html/reports/sh
ops/ $newfile/$newpdf"); print "\n";
...
I cannot get the rename function to work even if I use the same
directory. I don't get any errors and the file permissions are set
correctly on the files.

1) Don't post here - this newsgroup does not exist
2) What does
rename($from, $to) or warn("cannot rename '$from': $!");
tell you?
 
J

Jim Gibson

Mark said:
Hello,

I am new to PERL and I want to do a simple function (in LINUX):

find all files that have the extension pseudo.pdf and put the file
names in a file;
parse the file and change all file names current filename plus date:

pseudo+date+.pdf

Move the new file to pseudo directory :

I have written the code which seems to work without any errors and has
been accepted by PERL:

#!/usr/bin/perl -w
open (pdfs, "/var/www/html/reports/shops/pdflist.txt")
||Error('open','file');
@fnames=<pdfs>;
close (pdfs);

($second,$minute,$hour,$day,$month,$year,$weekday,$dayofyear,$isdst)=localtime
(time);
$cmonth=$month+1;
$cyear=($year % 100);
$fdate=$cmonth.'-'.$day.'-'.$cyear;
$ext='.pdf';
foreach $pdffile (@fnames2) {
$pdffile=$pdffile.$fdate.$ext;
}
$n=1;
foreach $fnames (@fnames) {
$cnt=index($fnames,".pdf");
$newfile=substr($fnames,0,$cnt);
$newpdf=$newfile.$fdate.$ext;
print "fnames: $fnames \n";
print "new file: $newfile \n";
print "newpdf: $newpdf \n";
print "old= /var/www/html/reports/shops/$fnames \n";
print "new= /var/www/html/reports/shops/$newfile/$newpdf \n";
rename("/var/www/html/reports/shops/$fnames","/var/www/html/reports/shops/
$newfile/$newpdf");
print "\n";

}


I cannot get the rename function to work even if I use the same
directory. I don't get any errors and the file permissions are set
correctly on the files.

Anyone know why this does not work?

Perhaps because the directory /var/www/html/reports/shops/$newfile does
not exist?
 
Ad

Advertisements

J

Joe Smith

Mark said:
rename("/var/www/html/reports/shops/$fnames","/var/www/html/reports/shops/
$newfile/$newpdf");

I don't get any errors ...

How can you say you don't get any errors when you don't even check
to see if any errors occurred?

rename($old,$new) or warn("rename($old,$new) failed: $!\n");

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top