Basic issue retrieve array or string from file using Storable retrieve

482 Views Asked by At

The problem is very simple but I can't seem to find it:

I store a $string to a $filename:

store [$tempstring], $filename2[$m];

I then try to retrieve it:

my $tempinput = retrieve ($filename2[$m]);

I believe I'm just getting the reference, not the string? Can I use a command to convert the data back to the original string?

1

There are 1 best solutions below

2
On BEST ANSWER
 my $ref = [ $tempstring ];

creates an array, assigns $tempstring to it (placing it in the first element), then returns a reference to that array.

So if you want the string back, you need to get the value of the first element of the referenced array.

 $ref->[0]

If you had done

 my $ref = \$tempstring;

instead of needlessly creating an array, you'd simply do

 $$ref

to get the string.