Perl
  Home arrow Perl arrow Page 4 - Using Perl With WDDX
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Using Perl With WDDX
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2002-08-07


    Table of Contents:
  • Using Perl With WDDX
  • The Big Picture
  • Packet Sniffer
  • Boyz 'N The Hood
  • All Mixed Up
  • Flying Toasters And Dancing Knives
  • Different Strokes
  • This Way Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Perl With WDDX - Boyz 'N The Hood
    ( Page 4 of 8 )

    Perl implements WDDX via its WDDX.pm module, which you can download from http://www.scripted.com/wddx/. This Perl module includes both a serializer and deserializer for WDDX, and also implements all the base data types defined in the WDDX specification.

    The basic procedure for serializing a WDDX packet with WDDX.pm is fairly straightforward: first create an object representation of the value you want to serialize, and then call the module's serialize() method to actually create the packet data. The following example illustrates the process of serializing a string variable with the module's string() method:

    #!/usr/bin/perl # include module use WDDX; # create WDDX object my $wddx = new WDDX; # create WDDX string object $obj = $wddx->string("Robin Hood"); # serialize and print object print $wddx->serialize($obj);
    Here's the output:

    <wddxPacket version='1.0'> <header/> <data> <string>Robin Hood</string> </data> </wddxPacket>
    In a similar manner, you can use the number() and boolean() methods to create numeric and Boolean data representations also.

    #!/usr/bin/perl # include module use WDDX; # create WDDX object my $wddx = new WDDX; # create WDDX number object $obj = $wddx->number(5); # serialize and print object print $wddx->serialize($obj);
    You can serialize integer-indexed arrays with the array() method.

    #!/usr/bin/perl # include module use WDDX; # create WDDX object my $wddx = new WDDX; # create a Perl array containing WDDX data objects my @colors = ( $wddx->string("red"), $wddx->string("blue"), $wddx->string("green"), ); # create a WDDX array object # note that the array() method must be passed a reference $obj = $wddx->array(\@colors); # serialize and print object print $wddx->serialize($obj);
    Note that, when serializing arrays, the array() method must be passed a reference to a Perl array containing WDDX data objects. These objects need not be of the same type.

    You can also serialize a Perl hash with the struct() method.

    #!/usr/bin/perl # include module use WDDX; # create WDDX object my $wddx = new WDDX; # create WDDX struct from a Perl hash # note that values of the Per,l hash must be WDDX data objects $obj = $wddx->struct( { "parrot" => $wddx->string("Polly"), "hippo" => $wddx->string("Harry"), "iguana" => $wddx->string("Ian") } ); # serialize and print object print $wddx->serialize($obj);
    This creates a <struct> containing name-value pairs corresponding to the elements of the hash.

    <wddxPacket version='1.0'> <header/> <data> <struct> <var name='hippo'> <string>Harry</string> </var> <var name='parrot'> <string>Polly</string> </var> <var name='iguana'> <string>Ian</string> </var> </struct> </data> </wddxPacket>
    Finally, you can generate a WDDX <recordset> with the recordset() method. This method accepts three arguments: a list of column names, a list of corresponding data types, and a two-dimensional list of values. Take a look at the following example, which might make this clearer:

    #!/usr/bin/perl # include module use WDDX; # create WDDX object my $wddx = new WDDX; # create WDDX recordset $obj = $wddx->recordset( ["ID", "NAME"], ["number", "string"], [ [1, "John"], [2, "Joe"], [3, "Mary"] ] ); # serialize and print object print $wddx->serialize($obj);
    You can create binary data packets with the binary() method, and timestamps with the datetime() method - I'll leave these to you to experiment with.

     
     
    >>> More Perl Articles          >>> More By icarus, (c) Melonfire
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT