Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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' )

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
Replies are listed 'Best First'.
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:/'; bless $fh, 'IO::File'; $zip->readFromFileHandle($fh); print $_->fileName, "\n" for $zip->members;

    holli, /regexed monk/
      Thanks very much for the reply, holli.
      Blessing the object to IO::File worked.
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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2015-10-07 20:48 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (200 votes), past polls