Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
[stevieb]: In msg, how do I message someone with a space in their name. For example, I want to privately message "Your Mother", but am unsure of how to do so. Link/tips?
[pryrt]: In the link brackets...
[stevieb]: guys, not *your* mother, "Your Mother" here on PM. Sheesh. Like I haven't spoken to your mom
[stevieb]: pryrt the brackets work in such a thing? I have nobody to test against. I will try :)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2018-03-23 00:38 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (287 votes). Check out past polls.