You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Michael Grant <mg...@grant.org> on 2002/09/15 05:42:48 UTC

[QUESTION] inconsistent eval

I'm having a very strage problem...

I flatten out an array using Data::Dumper and store it in a database.
Later, I need to unflatten it, so I use eval.  This works
*sometimes*.  In fact, it seems that it works the first time the
script is run in that httpd process, but never again.

    my $x = $cur_rec->{foo};
    print "x=".Dumper($x)."<p>";
    my $arrayref = eval($x);
    print "arrayref=".Dumper($arrayref)."<p>";

Sometimes I see this in my browser:

    x=$VAR1 = '$VAR1 = [ 34534, \'1031669584\' ]; '; 

    arrayref=$VAR1 = undef; 

Sometimes I see this:

    x=$VAR1 = '$VAR1 = [ 34534, \'1031669584\' ]; '; 

    arrayref=$VAR1 = [ 34534, '1031669584' ]; 

And sometimes I get just a blank screen in the browser as if I loaded
a blank page.

If it's indeed the eval that's causing the problem, can someone
recommend a better way to reverse what Dumper does?

Michael Grant

Re: [QUESTION] inconsistent eval

Posted by "Rafiq Ismail (ADMIN)" <ra...@joshua.dreamthought.com>.
I suspect it's the reuse of the $VAR1 global.  Quoting the eagle book,
since I'm crap at explaining things,

"The very first time the module is called , globals are initialised to
their undefined states in the way that conventional Perl scripts expect.
however in subsequent call the globals will contain information left over
from previous invocations of the script.  This will cause scripts that
depend on globals being initially undefined to fail.  Suspect this
probllems if your pages exhibit a pattern of progressive decay in which
they seem to work at first and then fail with increasing frequency."

Thus, try sticking a "my $VAR1;" in your code.



On Sun, 15 Sep 2002, Michael Grant wrote:

> I'm having a very strage problem...
>
> I flatten out an array using Data::Dumper and store it in a database.
> Later, I need to unflatten it, so I use eval.  This works
> *sometimes*.  In fact, it seems that it works the first time the
> script is run in that httpd process, but never again.
>
>     my $x = $cur_rec->{foo};
>     print "x=".Dumper($x)."<p>";
>     my $arrayref = eval($x);
>     print "arrayref=".Dumper($arrayref)."<p>";
>
> Sometimes I see this in my browser:
>
>     x=$VAR1 = '$VAR1 = [ 34534, \'1031669584\' ]; ';
>
>     arrayref=$VAR1 = undef;
>
> Sometimes I see this:
>
>     x=$VAR1 = '$VAR1 = [ 34534, \'1031669584\' ]; ';
>
>     arrayref=$VAR1 = [ 34534, '1031669584' ];
>
> And sometimes I get just a blank screen in the browser as if I loaded
> a blank page.
>
> If it's indeed the eval that's causing the problem, can someone
> recommend a better way to reverse what Dumper does?
>
> Michael Grant
>