AlphaStrike has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone!
I am using a module (http://hurring.com/scott/code/perl/serialize/).

to unserialize in perl the command is simply
$h = unserialize($data);

what I am stuck at is ... what is that data type? Do I treat it as a hash?
If anyone has used this module before, how do you access the data?
Many Thanks in advance!
Reality is but a perception of your being.

Replies are listed 'Best First'.
Re: accessing data serialised by PHP
by ivancho (Hermit) on Jan 22, 2009 at 04:02 UTC
    quoting from the page
    *array is unserialized as a hash, becuase PHP only has one array type +"array()", which is analagous to Perl hash's. When you try toseriali +ze a perl array, it's automagically converted into a hash with keys n +umbered from 0 up.
    ie, your $h will be a hashref, no matter what you serialized
      treating it as a hash seems to work
      thanks! =)
      Reality is but a perception of your being.
Re: accessing data serialised by PHP
by Your Mother (Archbishop) on Jan 22, 2009 at 05:48 UTC
    my $h = unserialize($data); print ref($h), $/;

    That'll tell you the reference type.

    On another note -- I don't know the package you're using and it might be fine but it hits a couple pet peeves of mine (lower case package names are reserved for pragmata and if it's decent, production quality code, it should be on the CPAN).

    I have used this in a couple of projects: PHP::Serialization. It worked great and it's even got some patches applied since and a new, solid maintainer attached.

Re: accessing data serialised by PHP
by tilly (Archbishop) on Jan 22, 2009 at 05:54 UTC
    Another option to consider is using a standard data interchange format. Such as JSON or YAML. (Of the two JSON is probably a better choice.)
Re: accessing data serialised by PHP
by setebos (Beadle) on Jan 22, 2009 at 03:38 UTC
    Just try the following (and post the output here):
    use Data::Dumper; print Dumper($h);
      the output is: $VAR1 = undef;
      so it does not recognise?
      the serialised data was originally a multidimentional area in PHP


      Reality is but a perception of your being.
        Hmmm I think I shall try serialising basic array. as looping it as a hash seems to have some output... probably better to do that since this is the first time I am doing it... =P thanks!
        Reality is but a perception of your being.