Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-06-24 12:25 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.