Mailing List Archive

Problem with %udat and references
Hello,

I have this simple code :

[.-
$req = shift;
@tmp=("1","a","zzz");
$udat{verdict} = \@tmp; # <- this doesn't work
# $udat{verdict} = ["1","bla","x"]; # <- this works
-]
<script>
document.location="somewhere.html";
</script>

When I reach somewhere.html, $udat{verdict} is populated only when the second line
is active (the one explicitly defining the arrayref as ["1","bla","x"]).
When I try with a reference to @tmp it is just a reference to an empty array.

What am I missing ? Anyone else experimenting such behaviour ?

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Problem with %udat and references [ In reply to ]
Le 12/04/2012 16:02, Jean-Christophe Boggio a écrit :
> When I reach somewhere.html, $udat{verdict} is populated only when the
> second line
> is active (the one explicitly defining the arrayref as ["1","bla","x"]).
> When I try with a reference to @tmp it is just a reference to an empty
> array.
>
> What am I missing ? Anyone else experimenting such behaviour ?

$udat{verdict} being a scalar, assigning an array to it makes it a
refference.

Embperl is perhaps assigning \@tmp as a reference of reference.

But if you say that it refences an empty array, it makes wonder if perl
just doesn't accept this assignation, WITHOUT
throwing an exception OR embperl just ignores this kind of behaviour.


puzzling ! :(


Bregs,

--
Nuguet romuald : kolikov@free.fr
---------------------------------
Internet est conçu avec des formats ouverts, donc :
- Afin de n'exclure personne
- Pour que vos données restent lisibles dans le futur.
Merci ne joindre que des fichiers au format ouvert : odt, pdf, html etc...
http://fr.wikipedia.org/wiki/Alternatives_ouvertes_aux_formats_ferm%C3%A9s
---------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Problem with %udat and references [ In reply to ]
Le 13/04/2012 10:54, kolikov a écrit :
> $udat{verdict} being a scalar, assigning an array to it makes it a refference.

I assign it a reference to an array

> Embperl is perhaps assigning \@tmp as a reference of reference.

Nope : I'm checking the array's content with Data::Dumper

> But if you say that it refences an empty array, it makes wonder if perl just doesn't accept this assignation, WITHOUT
> throwing an exception OR embperl just ignores this kind of behaviour.

This works :

$udat{verdict} = [];
push(@{$udat{verdict}},$_) foreach (@verdict);

Hopefully, @verdict is a very small array so it doesn't add too much overhead.

> puzzling ! :(

Crazy ! Maybe Gerald has some explanation or I've missed something in the documentation.

Thanks for your help,

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Problem with %udat and references [ In reply to ]
Hi,

Embperl is cleaning up all global variables at the end of the page, so they don't persist and interfere with the next request.

@tmp is cleaned up, before it gets written to %udat.

If you use "my @tmp " instead it should work, or you can avoid cleaning up @tmp by putting it's name into %CLEANUP with value 0 (http://perl.apache.org/embperl/pod/doc/Embperl.-page-5-.htm#sect_28)

Gerald


> -----Original Message-----
> From: Jean-Christophe Boggio [mailto:embperl@thefreecat.org]
> Sent: Thursday, April 12, 2012 4:02 PM
> To: embperl@perl.apache.org
> Subject: Problem with %udat and references
>
> Hello,
>
> I have this simple code :
>
> [.-
> $req = shift;
> @tmp=("1","a","zzz");
> $udat{verdict} = \@tmp; # <- this doesn't work
> # $udat{verdict} = ["1","bla","x"]; # <- this works
> -]
> <script>
> document.location="somewhere.html";
> </script>
>
> When I reach somewhere.html, $udat{verdict} is populated only when the
> second line is active (the one explicitly defining the arrayref as
> ["1","bla","x"]).
> When I try with a reference to @tmp it is just a reference to an empty array.
>
> What am I missing ? Anyone else experimenting such behaviour ?
>
> --
> Jean-Christophe Boggio -o)
> embperl@thefreecat.org /\\
> Independant Consultant and Developer _\_V
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Problem with %udat and references [ In reply to ]
Gerald,

Le 16/04/2012 14:36, richter@ecos.de a écrit :
> Embperl is cleaning up all global variables at the end of the page, so they don't persist and interfere with the next request.
> @tmp is cleaned up, before it gets written to %udat.

Ok ! Not very intuitive but makes sense. That explains everything.

> If you use "my @tmp " instead it should work, or you can avoid cleaning up @tmp by putting it's
> name into %CLEANUP with value 0 (http://perl.apache.org/embperl/pod/doc/Embperl.-page-5-.htm#sect_28)

Thanks a lot for the explanations and tips. It is very clear.

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org