Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Scripting problem - please help!

Reply
Thread Tools

Perl Scripting problem - please help!

 
 
Mark
Guest
Posts: n/a
 
      03-17-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Felix Geerinckx
Guest
Posts: n/a
 
      03-17-2005
On 17/03/2005, Mark wrote:

> ...
> 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?

--
felix
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      03-17-2005
In article <(E-Mail Removed) >, Mark
<(E-Mail Removed)> wrote:

> 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?


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      03-18-2005
Mark wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Scripting Language as Your Scripting Language DaveInSidney Python 0 05-09-2005 03:13 AM
Perl Scripting problem - please help Mark Perl Misc 1 03-18-2005 11:18 AM
Ruby (tied with Perl/sh) wins scripting languageshootout...slashdot... Richard Kilmer Ruby 2 06-13-2004 08:39 PM
Python is the best and most popular general purpose scripting language; the universal scripting language Ron Stephens Python 23 04-12-2004 05:32 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments