|
Posted by Jim Gibson on August 25, 2005, 2:53 pm
Please log in for more thread options
> I am currently working on a project that experiences intermittent
> errors, that we can not find any logical answer for. Attached is a
> copy of a method that will copy a given perl object....
>
> sub _deep_copy
> {
> my $self = shift;
> my $src_ref = $_[0];
> my $ref_type;
> my @new_array = ();
> my %new_hash = ();
> my $dest_ref;
>
> if (grep { $_ eq $src_ref } @Deep_copy_stack)
> {
> my $trace = join "<br/>", (caller);
> $self->_croak("deep_copy detected a loop<br/>$trace");
> }
> push (@Deep_copy_stack, $src_ref);
>
> if ( ref( $src_ref ) )
> {
> $ref_type = ref( $src_ref );
>
> if ($ref_type eq "HASH" )
> {
> my $key;
> my $value;
>
> # the src_ref points to a hash. Go through each key/value pair
> # and deep copy them over to the new_hash
> #
> while ( ($key, $value) = each %$src_ref )
> {
> $new_hash = $self->_deep_copy( $src_ref-> );
> }
>
> $dest_ref = \%new_hash;
> }
> elsif ($ref_type eq "ARRAY" )
> {
> # the src_ref points to an array. Go through each index and
> # deep copy them all over to the new_array
> #
> for ( my $ix = 0; $ix < scalar( @$src_ref ); $ix++ )
> {
> $new_array[$ix] = $self->_deep_copy( $$src_ref[$ix] );
> }
>
> $dest_ref = \@new_array;
> }
> elsif (UNIVERSAL::isa($src_ref, 'UNIVERSAL') &&
> UNIVERSAL::can($src_ref, 'copy'))
> {
> $dest_ref = $src_ref->copy();
> }
> else
> {
> print "<!-- $ref_type not supported -->\n";
> }
> }
> else
> {
> # $src_ref must be scalar. Copy it over and return it.
> $dest_ref = $src_ref;
> }
> pop (@Deep_copy_stack);
>
> return $dest_ref;
>
> } # End &_deep_copy()
>
>
>
> We have had reports of the error message (print "<!-- $ref_type not
> supported -->\n") appearing for objects that we know have the copy
> method, and that work at other times.
Is that really the error message printed? According to the code you
have posted above, the variable $ref_type should contain the return
value from ref($src_ref), which should be a string such as 'ARRAY' or
'HASH' or the name of a package (module). The error message should NOT
contain the substring '$ref_type'. If it does, then something is wrong.
If it does contain the name of a package/module, then that
package/module probably does not implement the copy() method.
>
> Most of our reports have come when the site is under heavy use. Has
> anyone seen problems where the UNIVERSAL::isa or the UNIVERSAL::can
> methods will fail under stress?
Hard as it is to accept, sometimes is just your program screwing up,
not Perl.
>
> We are using perlex/Windows and mod_perl/linux I think we are seeing on
> both platforms.
>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
|