Greetings and salutions;

I am using a subroutine I found to obtain the dimansions of a gif image. The sub returns a reference to the data but when I attempt to dereference it ie. $$height or $$width I get SCALAR(0xed880) SCALAR(0xed898) instead of the values I'm looking for. I have tried returning the vars $height and $width directly but the data they contain is innacurate when compared to the original image.

Does the expression: return \($width, $height);
require some other syntax to dereference properly?

Should the syntax be: return (\$width, \$height);
to dereference properly?

This is how I am attempting to use the subroutine:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Display the uploaded file. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # $MyFileName = "$ClassPath/classimg/$UpLoadedImg"; if (-e $MyFileName){ ($width, $height) = gifdim($MyFileName); if ($$height > 150){ # If the image is too tall for the display area # reduce the height to fit and recalculate the width $NewHeight = 150; $NewWidth = $$width - ($$height - 150); } elsif ($width > 150){ # If the image is too wide for the display area # reduce the width to fit and recalcualte the height $NewWidth = 150; $NewHeight = $$height - ($$width - 150); } # The image will fit in the display area so leave it alone else { $NewHeight = $$height; $NewWidth = $$width; } } # more code ... sub gifdim ($) { # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Get the dimensions of a gif # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $filename = $_[0]; open(GIF, $filename) || return (undef, undef); my $buf = ''; my $n = read GIF, $buf, 10; close GIF; return (undef, undef) if $n < 10; my ($head, $width, $height) = unpack("A6vv", $buf); ($head, $width, $height) = unpack("A6vv", $buf); return (undef, undef) unless $head =~ /^GIF8[79]a/; return \($width, $height); # return ($width, $height); }
I'm sure I'm missing something obvous but I'm stumped

My thanks to The Monastery
NereDoWell


In reply to dereferencing problem by NereDoWell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.