Rajib,

I believe you are having a problem because of what readdir returns.  readdir
returns an array of file names from the directory.  The first two files in
the directory are always the current directory (.) and the parent
directory(..).  If you stuff the contents of the readdir into an array and
filter out the directories (. and ..) the scripts works ok.  

I made a few changes to your script and it works.  See the changes below:

_CODE_

#!/bin/perl -w
#
use strict;

my ($file, @files);

opendir(DIR, "Testftp") || die "can't opendir $!";;
@files = grep {!/^\./ } readdir(DIR);
print "\n@files\n";
closedir DIR;

_CODE_END_

_OUTPUT_

test.txt test2.txt

_OUTPUT_END

It is always a good practice to use strict because it will help you find
coding problems that are difficult to find otherwise.

I hope this helps.

Mike Shelton


-----Original Message-----
From: Sengupta, Rajib (CC-Contractor)
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 5:47 PM
To: 'Jenda Krynicky'; [EMAIL PROTECTED]
Subject: RE: Want help for FTP using Perl


Thanks Jenda.
while trying it I am stuck again(though i am sure it is a trivial one for
you people):
first i am just trying to get the file name from a folder..

i am having a directory in C:/Perl/allperl/Testftp and inside this testftp
directory my test file is residing which is test.txt.

My perli script is in C:/Perl/allperl/ftp.pl
the code i had put is:
#!/bin/perl -w
    opendir(DIR, Testftp) || die "can't opendir $!";; 
    $filnam = readdir(DIR);
    print $filnam
    closedir DIR;
       

I am just trying to get the file name test.txt in the variable filnam.
This is causing me a problem as 
print<> on unopened filehandle 0 at ftp.pl
I think i am doing something wrong in using readdir and assigning it to
$filnam. Can you help me please?

Thanks,

Rajib Sengupta
ConAgra Business Systems
Peoplesoft AR and Order Management
222 South 15th St,North Tower(CT-930)
Omaha NE  68102
Phone: (402) 595-7928,Fax: (402) 595-7024





-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 2:37 PM
To: [EMAIL PROTECTED]
Subject: Re: Want help for FTP using Perl


From: "Sengupta, Rajib \(CC-Contractor\)" <[EMAIL PROTECTED]>
> 
> I am very new to unix as well as in perl. I had got a assignment in
> which I think perl will be the best bet. I am trying to accomplish the
> following:
> <sniped>

I'll reply by pointers to documentation.

If I say
        perldoc -f whatever
run that command in the shell (command prompt).

> The steps are
> 
> reading whatever file(there will be one file only ) is existing in a
> particuler folder and getting it's file name- i am not sure can we do
> this by perl,.i.e trying to get a file name from a folder.. 
> store the
> file name in a variable 

perldoc -f opendir
perldoc -f readdir
perldoc -f closedir

or 

perldoc -f glob

> getting current time stamp 

perldoc -f time

> creating a new file name 

perldoc -f rename

You should probably move the file to a different directory at this 
point to make sure the ca-unicenter will not be triggered again.

> executing ftp commands in perl script by using the variable 
names
> to put it to another server.

perldoc Net::FTP


Net::FTP's docs contain exaamples, the other things should be 
trivial.

There is one problem though. I do not know if ca-unicenter can do 
this for you, but you should only start renaming and FTPing the file 
unce it is complete.

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
                                        --- me
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to