note 4115 deleted from ref.wddx by felipe

From: Date: Mon, 10 Dec 2007 17:36:26 +0000
Subject: note 4115 deleted from ref.wddx by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133173@lists.php.net to get a copy of this message
Note Submitter: djm at web dot us dot uu dot net ---- I think it would be helpful for passing data between languages to show a direct translation of the above examples into Perl, using WDDX.pm 1.00 from CPAN. It took me awhile to figure out. To serialize: <PRE> #!/usr/bin/perl use WDDX; $wddx = new WDDX; $packet_id = $wddx->struct({}); $pi = 3.1415926; $packet_id->set("pi" => $wddx->number($pi)); # Suppose @cities came from database @cities = ("Austin", "Novato", "Seattle"); $packet_id->set("cities" => $wddx->array([map $wddx->string($_), @cities])); $packet = $wddx->serialize($packet_id); open(FP, ">cities.wddx"); print FP $packet; close(FP); </PRE> <P> To deserialize: <PRE> #!/usr/bin/perl use WDDX; open(FP, "<cities.wddx"); undef $/; # Slurp the whole file. $packet = <FP>; close(FP); $packet_id = new WDDX; $wddx_obj = $packet_id->deserialize($packet); $value = $wddx_obj->as_hashref(); print "pi is:<br>" . $value->{"pi"} . "<p>\n"; print "cities is:<br>\n"; $key = 0; foreach $val (@{$value->{"cities"}}) { print "$key => $val<br>\n"; $key++; } </PRE>

« previous php.notes (#133173) next »