in reply to prob in unfolding Dumper Data at the Server Side Socket prog

Take another look at the docs for Data::Dumper.

Data::Dumper->new() (not "New") does not return the serialized data structure, it returns a new Data::Dumper object.

$dump_object->Dump() returns the serialized data as a string containing perl code ready for eval().

In other words, you should send the output of $d->Dump() to the client and then restore it using eval $buffer;

Replies are listed 'Best First'.
Re^2: prob in unfolding Dumper Data at the Server Side Socket prog
by sroy.5 (Initiate) on May 19, 2007 at 15:53 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";