Re: How to send struct data over socket?



poohc1234@xxxxxxxxx wrote:
> Hi,
> Thanks for the reply. I have used Data::Dumper to stringify the
> structure into a long string, but the part that still confuses is once
> the long string is transmitted over the socket, how do I refill the
> data fields of the struct?

Did you actually read the documentation that was suggested to you in
the previous replies?

>>From `perldoc Data::Dumper` :
Given a list of scalars or reference variables, writes out
their contents in perl syntax. The references can also be
objects. The contents of each variable is output in a
single Perl statement. Handles self-referential structures
correctly.

The return value can be "eval"ed to get back an identical
copy of the original reference structure.

So, if you have

my $saved = Dumper(\%ReallyBigStruct);

and you've sent $saved through your socket, you can get back to your
data by doing:

my $restored = eval $saved;
my %CopyOfReallyBigStruct = %$restored;

(Or, if you want to skip the temp variable...)

my %CopyOfReallyBigStruct = %{eval $saved};

HTH,
Paul Lalli

.



Relevant Pages

  • Re: warnings on non-text hash keys? (was Re: better way using IO::Select and pool of non-blockig soc
    ... Also sprach Stuart Moore: ... >> stringified version of the reference to the socket. ... the program read a sign-off string from it, all I had to do was ...
    (comp.lang.perl.misc)
  • Re: Complex Specified Information - Pitman Formula
    ... Therefore a significant match between a reference and a test ... string is good evidence of non-random production. ... and there are no finite algorithms to compute their digits. ... probabilities of the different symbols the information source can produce. ...
    (talk.origins)
  • Re: String Reference Type
    ... All unary and binary operators have predefined implementations that are ... Therefore its always allocated in the heap and a variable of string ... As with all classes in this case y and x both reference the same String ... language depandant matter as below. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Abstract class variables question
    ... But as I think you've seen elsewhere in this thread, a value type can exist inside a class and in that case the value type is stored in the heap with the rest of the class instance. ... But as far as the "faster" goes, yes...to some extent value types have less overhead than reference types, and so can perform better in certain cases. ... Well, that would be true for a string object too, if there was any way to actually change a string. ... Seriously though, it is practically always the case that when you are writing an assignment to a reference, you're replacing the reference held by the variable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Measurement of pitch
    ... as the method used by the Pythagoreans. ... of these reference units in the quantity to be measured. ... vibrating string seems as good as anything. ... The string or pendulum in question could no doubt be specified exactly, ...
    (sci.physics)