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

How do I get this reference?

by sherab (Scribe)
on Feb 04, 2014 at 20:08 UTC ( [id://1073463]=perlquestion: print w/replies, xml ) Need Help??

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

Howdy monks!
I'm trying to pull out a value from this Dumper and I am able to almost grab all of it except for one bit (as you can guess it's a really long dump so I am trying to only put the relevant part in).

I am able to successfully pull out the 'image/jpeg' portion by this .....

$query->{'.tmpfiles'}->{$file_uploaded}->{'info'}->{'Content-Type'}

What I want is the "/usr/tmp/CGItemp12261" nugget. I can only get as far as..

$query->{'.tmpfiles'}->{$file_uploaded}->{'info'}->{'name'}

and I get totally perplexed.

Does anyone know how to get at this? Thank you so much in advance. (Clarification: For the curious: that location is a temp location for an uploaded file that I need to check).

$VAR1 = bless( { '.charset' => 'ISO-8859-1', '.tmpfiles' => { '*Fh::fh00001testforme.jpg' => { 'name' => bless( do{\(my $o = '/usr/tmp/CGItemp12261')}, ' +CGITempFile' ), 'hndl' => bless( \*{'Fh::fh00001testforme.jpg'}, 'Fh' ), 'info' => { 'Content-Type' => 'image/jpeg', 'Content-Disposition' => 'form-data; name="FileFT1"; f +ilename="testforme.jpg"' } } },

Replies are listed 'Best First'.
Re: How do I get this reference?
by AnomalousMonk (Archbishop) on Feb 04, 2014 at 22:12 UTC

    FWIW, had this been an ordinary hash or an object reference for which it was really, really necessary to violate encapsulation, something like the following (shorn of bless-ed confusion) might have been served:

    >perl -wMstrict -MData::Dumper -le "my %hash = (foo => {bar => {name => do { \(my $o = 'HiThere') }}}); ;; my $hash_ref = \%hash; print Dumper $hash_ref; ;; my $scalar_ref = $hash_ref->{foo}{bar}{name}; my $scalar = $$scalar_ref; print qq{'$scalar'}; " $VAR1 = { 'foo' => { 'bar' => { 'name' => \'HiThere' } } }; 'HiThere'
Re: How do I get this reference?
by Kenosis (Priest) on Feb 04, 2014 at 20:16 UTC

    Is this an object for which a method exists that provides access to the wanted value?

      Special thanks to Kenosis. I just needed to correctly use the tmpFileName method to read it. Case closed;

        Great that you solved it!

      Thanks for jumping in! I am using CGI to take a bunch of values from a page and a file upload. The reason I am jumping through these hoops is to determine the MIME type and discovered that CGI's MIME checking just reads the extension and can easily be fooled (as well as all other perl mods) but by using linux's mime checking I get better results if I could only apply it against the actual file being uploaded. (Sorry about being so wordy on this)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1073463]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-20 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found