When you speak
print $ref;
you partially instruct Perl to convert $ref to a string (since only strings can be print ed). It turns out that links by default do not turn into very useful lines.
You need to turn $ref into a string that you can send over the wire and then decode on the other side to return the data. This process is called serialization. Data::Dumper output is actually a valid serialization of its arguments, but the main serialization module in Perl Storable .
Procedurally, you can say [1]
use Storable qw(nfreeze);
on the one hand and
use Storable qw(thaw); ... my $ref = thaw($line);
with another.
There is also an OO interface; read the Storable documentation for more information.
[1]: Pay attention to yaddayaddas. This is incomplete code that simply illustrates the key differences from your code.
source share