sroy.5 has asked for the wisdom of the Perl Monks concerning the following question:

I have wrapped the data using Dumper from the Client side and wanted to pass the data using syswrite through Socket and wanted to use those data in the Server Side.
Client Side ----------- my %c = ( name => "Apple", value => "25", ); my $a = [ %c ]; my $d=Data::Dumper->New([ %c , $a]); $Server->syswrite( $d , length($g)); Server Side ----------- $Scoket->recv($buffer,$buff_len);
Not able to unwrap $buffer Tried with Dumper( eval $buffer->Dump). I could get only this much which throws the error as::>
Can't call method "Dump" without a package or object reference at .... +.
The Dumper gives the value as Dumper($buffer) ::>
"$VAR1 = \'Data::Dumper=HASH(0x8adff94)\';"
I am looking for the way how could I get back the data in the Server Side. Thanks SR

Replies are listed 'Best First'.
Re: prob in unfolding Dumper Data at the Server Side Socket prog
by Joost (Canon) on May 19, 2007 at 14:51 UTC
      Thanks for the pointing out the $d->Dump to be send with the syswrite. Now I am getting the value in Server Side. But eval is not giving the data back. The output is coming as follows::> Dumping the buffer $VAR1 = undef;
      Though While I am again using
      $socket->recv($buffer , BUFF_LEN); my $a = [ $buffer ]; my $d = Data::Dumper->new([ $buffer , $a ]); my $c = $d->Dump; print Dumper($c);
      The above code is unfolding the details. can you pls comment on this.
      Re,
      SR
        Ok, well a few comments:

        • The output is coming as follows::> Dumping the buffer $VAR1 = undef;
          That's certainly not the output of the code you just posted.

        • $socket->recv($buffer , BUFF_LEN); will break the message if BUFF_LEN is smaller than the actual size of the message sent.

        • my $a = [ $buffer ]; my $d = Data::Dumper->new([ $buffer , $a ]); my $c = $d->Dump;
          What's that all about? You are receiving a serialized structure in $buffer you should not-store that string in a new structure and serialize it again, you should eval() the $buffer. As already stated by me and others in this thread.

        • You appear to be confused about the use of Data::Dumper. Let me just note that it's easy to test the dump/restore stage without sending anything across a pipe/stream/socket:
          #!/usr/bin/perl -w use strict; use Data::Dumper; my $fancy_struct = { a => "aaah", b => "beeh", }; my $dumper = Data::Dumper->new([$fancy_struct]); $dumper->Purity(1); my $serialized = $dumper->Dump; print "Serialized form: $serialized"; my $VAR1; eval $serialized || die; my $new_fancy_object_clone = $VAR1; print "a = $new_fancy_object_clone->{a}\n";

Re: prob in unfolding Dumper Data at the Server Side Socket prog
by NetWallah (Canon) on May 19, 2007 at 14:52 UTC
    Did you notice that your statement
    $Server->syswrite( $d , length($g));
    uses $g, not $a ?

    $a is not the best name to use anyway, since sort uses it.

         "An undefined problem has an infinite number of solutions." - Robert A. Humphrey         "If you're not part of the solution, you're part of the precipitate." - Henry J. Tillman

Re: prob in unfolding Dumper Data at the Server Side Socket prog
by blazar (Canon) on May 19, 2007 at 14:59 UTC
    my $a = [ %c ]; my $d=Data::Dumper->New([ %c , $a]); $Server->syswrite( $d , length($g));

    I'm not familiar with D::D's OO interface, but I believe that you want $d->Dump there, not the object itself. And what the heck is $g anyway?

    Not able to unwrap $buffer Tried with Dumper( eval $buffer->Dump).

    At the receiving end you want a simple eval, nothing that has to do with D::D.