SPUG: Strange code effect

BenRifkah Bergsten-Buret mail.spammagnet at gmail.com
Wed Dec 23 12:36:02 PST 2009

See comments below.

On Tue, Dec 22, 2009 at 8:49 PM, Joseph Werner <telcodev at gmail.com> wrote:

> Hey guys [and gals],
> I encountered a strange Perl code phenomenon dealing with some object
> references, and and array of object references. Specifically, I could
> not shift a reference to an object off of an array of object
> references. More troubling, I also was unable to use the object
> references in a boolean context. I have written code very similar to
> this dozens if not hundreds of times and never encountered this type
> of problem...
> The code is all proprietary,  and the powers that be frown on release
> of any sort, so I will pseudo code what I am talking about. We are
> running Active State Perl 5.10 on a Win32 platform, if that matters
> my $some_parms = shift;
> my $objhref = get_objects($some_parms);
> # $objhref = {
> #           '01' => bless( {}, 'ASpecialObject' ),
> #           '03' => bless( {}, 'ASpecialObject' ),
> #           '02' => bless( {}, 'ASpecialObject' )
> #         };
Have you tried assigning anything from $objhref directly at this point?  For
example, do you get an error if you try to do $myobj = $objhref->{01}?

> # ASpecialObject class does have the <=> overloaded
> # But I cannot see the making a difference...
> # Sorting works fine:
> my @arrayoforefs;
> eval {
>   @arrayoforefs = sort { $a <=> $b } values %{$objhref};
> }
> # Error checks ignored

Since you've wrapped this in an eval it seems like you're expecting
exceptions to be thrown.  Why ignore them?  See if there is an exception
that might lead you in the right direction.

Also, are you able to access anything within @arrayoforefs without using an
assignment?  For example what happens when you do warn "arrayofrefs[0]:
@arrayofrefs[0]"?  Do the server crash?

> # Server dies silently at the following statement:
> my $chosenO = shift @arrayoforefs;
> # If I do this instead:
> my $chosenO = $arrayoforefs[0];
> # Then this causes the server to silently crash:
> return unless $chosenO;

You've said "server dies silently" and "silently crash" but I'm not clear
what you mean.  Is this two different things or the same?  By "crash" do you
mean that the server process exits with a core dump?  Is this an Apache
server?  Mod_perl?  When perl "dies" it generates a message.  Also, in my
experience when Apache dumps core it puts a message in the log but you've
said "silently" so perhaps something else is going on.

My suggestion is to code up the simplest case you can where the problem is
encountered.  Strip out as much code as possible that doesn't directly
relate to what you're doing.  For example, the following script can be run
outside of your web server and outside of your Mason environment:


use strict;
use warnings;
use lib "/my/code/path";
use ASpecialObject;

my $objects = {
 01 => ASpecialObject->new(),
 02 => ASpecialObject->new(),

my @sorted = sort {$a <=> $b} values %{$objects};

#Does this result in the same problems you're having?
my $chosen0 = shift @sorted;
print "If you see this then the script is done\n";

You'll probably have to include some object initialization code but if you
still have problems with this then you know the problem is somewhere in
ASpecialObject.pm.  Then you can start stripping out the code from there to
find the minimum amount of code that causes the problem.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20091223/4f192924/attachment.html>

More information about the spug-list mailing list