Gossamer Forum
Home : General : Perl Programming :

FileHandle

Quote Reply
FileHandle
I'm using filehandle like this
my $file= FileHandle->new();
for a script using Net::FTP. Everytime the ftping is done, get a wierd file in the directory with the script like
FILE=GLOB(907303ac4) or something like that.
I close it like this
close($file);
so I was wondering if there was anything else i would have to do to stop this from happening.
thanks.
Lavon Russell
LookHard Mods
lavon@lh.links247.net
Quote Reply
Re: [Bmxer] FileHandle In reply to
This:

my $file= FileHandle->new();

...isn't a filehandle, it is a method. It is similar to...

my $file = new FileHandle;

Which means in FileHandle.pm you'd normally have something like:

Code:
sub new {
my ($self) = shift;
return bless {}, $self;
}

You need someting like ....close(HANDLE);

...or with Net::FTP, $ftp->quit;

Last edited by:

RedRum: Oct 20, 2001, 4:35 AM
Quote Reply
Re: [RedRum] FileHandle In reply to
Just so I'm clear, why do you need to close something?....you shouldn't have to with Net::FTP

Could I/we see some of the code?
Quote Reply
Re: [RedRum] FileHandle In reply to
Oh, i wasn't sure about FileHandle. I don't use modules much. but um
here's some code :
Code:
my $ftp_a = Net::FTP->new("lh.links247.net", Debug => 0) or &fail("Could not connect to download server: $!. Please try later.");
my $ftp_b = Net::FTP->new("$site", Debug=> 0);

$ftp_a->login("user","pass") or &fail("Could not login to download server: $!");
$ftp_b->login("$user","$pw") or &fail("Could not login to your server: $!");

my $fh = FileHandle->new();
foreach (@cgi_list) {
$ftp_a->cwd("$dir") or &fail("Could not cd to install directory $!");
$ftp_a->get($_,$fh) or &fail("Could not get file $_ from server : $!");
$ftp_b->cwd("$cgi") or &fail("Could not cd to $cgi : $!");
$ftp_b->put($fh,$_) or &fail("Could not put file $_ to $site : $!");
$ftp_b->quot('SITE','CHMOD','755',$_);
}
close ($fh) or warn "Cannot close filehandle: $!";
$ftp_a->quit or &fail("Could not close connection with download server properly: $!");
$ftp_b->quit or &fail("Could not close you connection properl: $!");
@cgi_list is the array with the files i have as you probably already know. I knew FileHandle->new dealt with the IO module, but not sure why its creating those files. The files are filled with the data of the files it sends.
Lavon Russell
LookHard Mods
lavon@lh.links247.net
Quote Reply
Re: [Bmxer] FileHandle In reply to
nevermind i found a way.
not sure if its the right one, but
i'm using a simple unlink on the filehande.pm
I deleted the close($fh) and it still did it, so i tried
Code:
......
$ftp_b->put($fh,$_) or &fail("Could not put file $_ to $site : $!");
$ftp_b->quot('SITE','CHMOD','755',$_);
unlink($fh);

that gets rid of the files. BTW... ftp->quot('SITE','CHMOD','755',$_);
that work with anyone not using unix will it?
Lavon Russell
LookHard Mods
lavon@lh.links247.net
Quote Reply
Re: [Bmxer] FileHandle In reply to
Im just wondering what this actually is:

my $fh = FileHandle->new();

....and why are you trying to close it?

It isn't needed.
Quote Reply
Re: [RedRum] FileHandle In reply to
I only put close because i thought that would be the thing to delete those files, sort of like closing the session. But ever since you told me that was wrong, I've been thinking that was dumb b/c i should have known it didn't need a close, because i never opened it. i think maybe when i was looking at docs for FileHandle, i read one that dealt with databases and not the module.
Lavon Russell
LookHard Mods
lavon@lh.links247.net
Quote Reply
Re: [Bmxer] FileHandle In reply to
Hey sorry for the late reply, I've been working on a guestbook :)

http://213.106.6.135/...in/guest/woguest.cgi


Anyway....the reason for that weird file you are getting is because of this:

my $fh = FileHandle->new();

You are creating an object with that code and then further down you are "putting" and "getting" $fh which is actually only an object at that point. $fh will be the value of whatever sub new does to it in FileHandle.pm

For example if I had a module called Bla.pm and did:

my $foo = new Blah;

.....and sub new in Bla.pm was:

Code:
sub new {
return bless {}, $_[0];
}

....then if you tried to print $foo it would print Blah(0x823423) or something similar.

Likewise if I tried to put/get $foo with Net::FTP it would create a file with that name.

How ever if you added another sub to Blah.pm like:

Code:
sub file {
return "file.txt";
}

....and then tried to put/get $foo->file; then you'd get a decent filename :)

I hope that made a tiny bit of sense....
Quote Reply
Re: [RedRum] FileHandle In reply to
nice guestbook Smile
I understand what you mean, when you say
return bless {}, $_[0];
would bring back the wierd file.

Lavon Russell
LookHard Mods
lavon@lh.links247.net