The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Convert::PerlRef2String - Perl extension for converting simple PERL references to compressed string and vice versa

SYNOPSIS

The following script

  use Convert::PerlRef2String;
  use Convert::PerlRef2String;
  use Data::Dumper;
  my $perl = {
          'Order' => {
                       'BookName' => 'Programming Web Serivices with Perl',
                       'Id'       => '0-596-00206-8',
                       'Quantity' => '500'
                     },
          'Payment' => {
                         'CardType'  => 'VISA',
                         'ValidDate' => '12-10-2006',
                         'CardNo'    => '1234-5678-9012-3456',
                         'Bearer'    => 'Kai Li'
                       }
        };
  my $string = perlref2string($perl);
  print $string,"\n";
  my $perlref = string2perlref($string);
  print Dumper($perlref);

produces this output:

  H4sIAAAAAAAAA32RzarCQAxG9z5FFheycSCttiqi4M9GFK1XqetoBx20rYyjUqTvbtVeuYJtlplz
  vknIj9/7taADtwq8C2c6kBqh0/1ofxT243g/5VA+MfR0vNUchirawkquYSG1uqiNPMFVmR14Uh+w
  Wpg1Cl4pJJyWK4hsckWzhJ+fOTLKJC/LIcLvaPo/Aj1OQhmZ8r0ybsA6WCbHfDN/tOgVj5LhPh9U
  MGST85YtLBI2kVtqPT6Zxn9KrS4ct9EULcr0Wt0pd/uSdX4fHLOCicIiOn0/pO3KHXfoF8XsAQAA

  $VAR1 = {
          'Order' => {
                       'BookName' => 'Programming Web Serivices with Perl',
                       'Id' => '0-596-00206-8',
                       'Quantity' => '500'
                     },
          'Payment' => {
                         'CardType' => 'VISA',
                         'ValidDate' => '12-10-2006',
                         'CardNo' => '1234-5678-9012-3456',
                         'Bearer' => 'Kai Li'
                       }
        };

While a slightly different version (passing PERL code to sunroutine perlref2string instead of reference)

  use Convert::PerlRef2String;
  use Convert::PerlRef2String;
  use Data::Dumper;
  my $perl = q|{
          'Order' => {
                       'BookName' => 'Programming Web Serivices with Perl',
                       'Id'       => '0-596-00206-8',
                       'Quantity' => '500'
                     },
          'Payment' => {
                         'CardType'  => 'VISA',
                         'ValidDate' => '12-10-2006',
                         'CardNo'    => '1234-5678-9012-3456',
                         'Bearer'    => 'Kai Li'
                       }
        };|;
  my $string = perlref2string($perl);
  print $string,"\n";
  my $perlref = string2perlref($string);
  print Dumper($perlref);

produces essentially the same result.

DESCRIPTION

This is a handy tool for who wants to exchange simple PERL references (except for subroutine references) over the Internet as compressed strings. When both the sender and receiver are PERL programs you can use this tool as an alternative to exchanging XML files.

EXPORT

perlref2string and string2perlref.

AUTHOR

Kai Li, <kaili@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Kai Li

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.