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

Quick question, and I really feel like a goon for asking it.
I'm using Image::Magick to resize pictures - follows is a snippet of a function I'm running and the invocation of it:

sub resize { my $img=shift; my $size=shift; my $geometry; if ( orientation($img)=="portrait" ){ $geometry="x" . $size; } else { $geometry=$size; } print "RESIZE: Geometry is $geometry, received $size, and it s +hould be $sizes{$size}, pic is $img<BR>"; $img->Resize(geometry=>$geometry); return $img; }

What I'm seeing, when calling it like so:
my $tmppic=resize($pic,$sizes{$size}); and: $ret=$tmppic->Write("jpeg:$dest"); my $tmpheight=$pic->Get('columns'); print "Orig: $tmpheight . Write to $tmppic $dest returned $ret +<BR>";
Is rather troubling $pic itself changes the size, it seems that sub resize() received a reference instead of a value, but try as I might I couldn't copy the thing properly, including creating a new object and assigning.

I'm sure I'm missing something awfully basic here. Anyone feel like slapping me with some clue?

Thanks,
Nir.

Replies are listed 'Best First'.
Re: Object passed by reference or value?
by Juerd (Abbot) on Jun 01, 2003 at 14:59 UTC

    I'm sure I'm missing something awfully basic here.

    The basic something that you are missing is: objects in Perl are references to blessed value containers.

    With $img = shift, you're copying the reference, not the object itself. Try $img = shift->Copy;.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }