Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
[Tux]: None work for me. My dead key is AltGr (right Alt)
[Tux]: And I just tested, neither do other Tk apps :) (95% of my Tk Apps is either just monitoring (no input) or input of just numbers). Something to investigate then
[choroba]: Maybe something like this?
[choroba]: I vaguely remember we had problems with dead keys in Tk at $work - 2, but I forgot all the details
[choroba]: but it was worse on MSWin than on Linux
[choroba]: (and OSX didn't exist yet)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-09-25 20:45 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (290 votes). Check out past polls.