473,606 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ 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+.pd f

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,$minut e,$hour,$day,$m onth,$year,$wee kday,$dayofyear ,$isdst)=localt ime(time);
$cmonth=$month+ 1;
$cyear=($year % 100);
$fdate=$cmonth. '-'.$day.'-'.$cyear;
$ext='.pdf';
foreach $pdffile (@fnames2) {
$pdffile=$pdffi le.$fdate.$ext;
}
$n=1;
foreach $fnames (@fnames) {
$cnt=index($fna mes,".pdf");
$newfile=substr ($fnames,0,$cnt );
$newpdf=$newfil e.$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.g eneration.net
Jul 19 '05 #1
3 3275
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****@generat ion.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+.pd f

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,$minut e,$hour,$day,$m onth,$year,$wee kday,$dayofyear ,$isdst)=localt ime
(time);
$cmonth=$month+ 1;
$cyear=($year % 100);
$fdate=$cmonth. '-'.$day.'-'.$cyear;
$ext='.pdf';
foreach $pdffile (@fnames2) {
$pdffile=$pdffi le.$fdate.$ext;
}
$n=1;
foreach $fnames (@fnames) {
$cnt=index($fna mes,".pdf");
$newfile=substr ($fnames,0,$cnt );
$newpdf=$newfil e.$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,$ne w) or warn("rename($o ld,$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
2464
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 not very conversant with Python at this stage. that could change soon though.
2
1849
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 application's Perl APIs from Python. Essentially I am looking for a package that would read a perl module and allow me to access the functions in that module from Python. For example the Communigate Pro messsaging server has a Perl api, but...
42
4068
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. I'm not interested on which language is better in *general*, just for my purpose. My area of research is in CAD algorithms, and I'm sensing the need to resort to something more expedient than C++, bash scripting, or sed scripting.
17
3091
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
1792
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 construct the HTML pages. Here is what I do. 1) Show a web page and accept values from the web-user. 2) When the User presses "Submit", I construct a message and send it across the UDP socket to the backend.
1
3993
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 are not intimately familiar with Perl, then perhaps you can still help by reading through the lines here... I'm looking for a templating system in a Classic ASP environment that works like HTML::Template in Perl. I've actually used HTML::Template
12
2341
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
4292
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 out. Any information on this topic will be appreciated. Thanks And Regards, Prakhar
4
5435
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 the number of duplicate rows based on a particular cell value of each these duplicate rows. I mean all the cell values of a row will not be duplicated but a individual columns cell value will be duplicated and I need to create a separate excel with...
0
7962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8107
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2452
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 we have to send another system
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.