NereDoWell has asked for the wisdom of the Perl Monks concerning the following question:
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:
I'm sure I'm missing something obvous but I'm stumped# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 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); }
My thanks to The Monastery
NereDoWell
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dereferencing problem
by Mr. Muskrat (Canon) on Mar 14, 2003 at 22:14 UTC | |
|
Re: dereferencing problem
by dga (Hermit) on Mar 14, 2003 at 22:11 UTC | |
by NereDoWell (Initiate) on Mar 14, 2003 at 23:04 UTC | |
|
Re: dereferencing problem
by bbfu (Curate) on Mar 14, 2003 at 22:12 UTC | |
|
Re: dereferencing problem
by thpfft (Chaplain) on Mar 15, 2003 at 17:53 UTC | |
|
Re: dereferencing problem
by Desdinova (Friar) on Mar 14, 2003 at 22:49 UTC | |
by NereDoWell (Initiate) on Mar 14, 2003 at 23:19 UTC |