Perl
  Home arrow Perl arrow Page 4 - Using Perl With WDDX
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: 2 stars2 stars2 stars2 stars2 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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 moduleuse WDDX;# create WDDX objectmy $wddx = new WDDX;# create WDDX number object$obj = $wddx->number(5);# serialize and print objectprint $wddx->serialize($obj);
    You can serialize integer-indexed arrays with the array() method.

    #!/usr/bin/perl # include moduleuse WDDX;# create WDDX objectmy $wddx = new WDDX;# create a Perl array containing WDDX data objectsmy @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 objectprint $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 moduleuse WDDX;# create WDDX objectmy $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 objectprint $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 moduleuse WDDX;# create WDDX objectmy $wddx = new WDDX;# create WDDX recordset$obj = $wddx->recordset( ["ID", "NAME"], ["number", "string"], [ [1, "John"], [2, "Joe"], [3, "Mary"] ]);# serialize and print objectprint $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

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway