Hi
I was trying to get NET::Ftp to work in Apache to post statistics via FTP.
These stats are in memory and are manipulated before being posted. I wanted
to tie a filehandle so that Net::FTP would call my READ code. So I
could just go
MyNetFTPObject->put(TIED_FILE_HANDLE ,
remote_file)
I cannot get this to work and it seems to boil down to this fabricated example. Note that the READ / OPEN etc routines in PRCTiedHandle prints out the READ / OPEN 'debug' message. A summary of the example is: 1) Tie
and open a filehandle , buffering data in array.
2) sysread
from within main::
3) Pass
filehandle to subroutine and go sysread
4) sysread
again from within main
The result is that the 'main' sysread work, but the
sysread in the subroutine 'fails' (returns undef).
use strict;
use PRCTiedHandle; my ( $len , $buf, $blksize) = (0,"",120); my $file = 'c:\a.txt'; tie *FILMAIN, PRCTiedHandle::;
open *FILMAIN, $file or die "cannot open $file" ; print "Main 1 before sysread 1 filmain=", *FILMAIN, " ref=", ref(\*FILMAIN) ,"\n"; sysread(*FILMAIN,$buf="",$blksize); print "Main 2 after first
sysread\n";
&readIt(*FILMAIN); $len = sysread(*FILMAIN,$buf="",$blksize); print "Main 3 after sysread 2\n"; close FILMAIN; sub readIt (*)
{ *FILSUB= shift; print "readIt filsub=",*FILSUB, " ref=",ref(\*FILSUB),"\n"; print "readIt filsub and filmain are equal\n" if (*FILSUB eq *FILMAIN); return $len = sysread(*FILSUB,$buf="",$blksize); }; When I run the above I get the following output from various print
statements:
--- snip ---- TIEHANDLE called OPEN c:\a.txt: countRecs=11 Main 1 before sysread 1 filmain=*main::FILMAIN ref=GLOB READ entered Main 2 after first sysread readIt filsub=*main::FILMAIN ref=GLOB readIt filsub and filmain are equal READ entered Main 3 after sysread 2 CLOSE called --- snip ----
The READ routine in the handler is called correctly from the main routine. However, when I call it from the readIt subroutine then 'nothing' happens. (If I substitute FILEMAIN for FILESUB in readIt then it works of course). There appears to be a logical difference between the tied FILMAIN and the passed FILSUB, even though they 'point' to the same thing. I guess I really don't understand what is Tied. I know TISMTOWTDI, however, I have tried the complete Heinz 57 varieties of passed referenced and dereferenced variables. All have failed. After I get this example working I can mod FTP::Net to accept tied Filehandles. Can anyone give me a few pointers? I prefer them to references (C background, you know) Paul Cotter www.powermagic.net |