boboson has asked for the wisdom of the Perl Monks concerning the following question:

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?

Replies are listed 'Best First'.
Re: get the filename from CGI::UploadEasy
by doc_faustroll (Scribe) on Apr 03, 2006 at 01:42 UTC
    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
by zer (Deacon) on Apr 03, 2006 at 07:10 UTC
    foreach (keys %info){ print; }
    this will give you the names
      you missed the reference!
Re: get the filename from CGI::UploadEasy
by boboson (Monk) on Apr 03, 2006 at 07:57 UTC
    answer to my question is a mix of your suggestions, thanks!
    my $info = $ue->fileinfo; my %HoH = %{$info}; foreach (keys %HoH){ print; }