473,480 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Perl Scripting problem - please help!

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
bu****@nospam.generation.net
Jul 19 '05 #1
3 3254
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
Jul 19 '05 #2
In article <31**************************@posting.google.com >, Mark
<bu****@generation.net> 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 =---
Jul 19 '05 #3
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
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2453
by: Chris | last post by:
Hi I am posting this on both the perl and python groups My intention is not to start a war or anything else, I would just like some pragmatic advice. My apologies to the python group I am...
2
1840
by: Chris Kacoroski | last post by:
Hi, I would like to use Python for several scripting tasks I have, but the applications I am scripting against only export a set of Perl API's. Is there any package that makes it easy to use an...
42
4019
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
17
3072
by: Michael McGarry | last post by:
Hi, I am just starting to use Python. Does Python have all the regular expression features of Perl? Is Python missing any features available in Perl? Thanks, Michael
1
1781
by: Hari | last post by:
Hi, I am a newbie to Perl CGI. I am developing an application with a web front end and C language module at the backend. The interface between them is a UDP socket. I am using Perl to...
1
3980
by: C. Olive | last post by:
Environment: Classic ASP running on IIS v5.1 Scripting Language: VBScript I suppose someone would have to be somewhat familiar with Perl in order to answer this question specifically. If you...
12
2313
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
2
4274
by: prakharv | last post by:
Hi All, I would like to upload a image file from my web page to the server using perl scripting. Please, if any one knows regarding this or has the source code for the same, please help me...
4
5418
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.