Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Convert FileHandle to IO::File object

by ganeshk (Monk)
on Jul 28, 2005 at 08:58 UTC ( #478883=perlquestion: print w/ replies, xml ) Need Help??
ganeshk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
I want to unzip a Zip file(uploaded from browser) in a
CGI program.
I just get the file handle for the zip file.
This is the Data::Dumper output of the object
bless( \*{'Fh::fh00001test.zip'}, 'Fh' )

I am using Archive::Zip module. So I guess I should do
something like this
my $zip = Archive::Zip->new(); $zip->readFromFileHandle($fh);
But what the readFromFileHandle method expects an
IO::File object. So how can I convert the file handle
object to the IO::File object.
Thanks in advance for the answers. I

Comment on Convert FileHandle to IO::File object
Select or Download Code
Re: Convert FileHandle to IO::File object
by holli (Monsignor) on Jul 28, 2005 at 09:40 UTC
    You could try to simply bless it into an IO::File object. The following works, but i am not sure if it will work in CGI context.
    use strict; use warnings; use IO::File; use Archive::Zip; my $fh; my $zip = Archive::Zip->new(); open $fh, '<', 'c:/test.zip'; bless $fh, 'IO::File'; $zip->readFromFileHandle($fh); print $_->fileName, "\n" for $zip->members;


    holli, /regexed monk/
      Hi,
      Thanks very much for the reply, holli.
      Blessing the object to IO::File worked.
      Thanks
Re: Convert FileHandle to IO::File object
by umbra (Acolyte) on Jul 28, 2005 at 09:44 UTC
    seems to me that to unzip archive You should use
    ExtractMember or ExtractTree methods rather then readFromFileHandle

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://478883]
Approved by monkey_boy
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-28 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls