get the filename from CGI::UploadEasy
boboson
created: 2006-04-02 17:47:47
I am using CGI::UpladEasy to upload files from a webform. When I run the example application below:
use strict;
use warnings;
use CGI::UploadEasy;
use Data::Dumper;
my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/directory');
my $info = $ue->fileinfo;
my $cgi = $ue->cgiobject;
print $cgi->header('text/plain');
print Dumper $info;
I get the following output
$VAR1 = {
          '1143232971-HIQ050430376_mindre_33.jpg' => {
                                                       'ctrlname' => 'imgfile',
                                                       'bytes' => '9233',
                                                       'mimetype' => 'image/pjpeg'
                                                     }
        };

This is probably a basic question, but how do I get the filename '1143232971-HIQ050430376_mindre_33.jpg' of the uploaded file?
Re: get the filename from CGI::UploadEasy
created: 2006-04-02 21:42:36
You are in the land of a reference to a hash of hashes. If you are just learning the language and the idioms are unfamiliar to you, you might explicitly dereference first off to simplify

read perldoc perlref

my $ref = $ue->filinfo;
my %HoH = %{$ref};
Then you have a hash or hashes which is a hash in which the keys are the filenames and the values are hash references.

the canonical print idiom from perldoc perdsc is: (although your taste may differ once you develop it):

 foreach my $filename ( keys %HoH ) {
            print "$filename: { ";
            for my $key ( keys %{ $HoH{$filename} } ) {
                print "$key =$HoH{$filename}{$key} ";
            }
            print "}\n";
        }

Re: get the filename from CGI::UploadEasy
zer
created: 2006-04-03 03:10:50
foreach (keys %info){
print;
}
this will give you the names
Re^2: get the filename from CGI::UploadEasy
created: 2006-04-03 20:23:34
you missed the reference!
Re: get the filename from CGI::UploadEasy
created: 2006-04-03 03:57:03
answer to my question is a mix of your suggestions:
my $info = $ue->fileinfo;
my %HoH = %{$info};

foreach (keys %HoH){
	print;
}

perlmonks.org content © perlmonks.org and Anonymous Monk, boboson, doc_faustroll, zer

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03