Object Reference

On Fri, 19 Jul 2002, Jason White wrote:
> I'm using Data::Dumper to save and restore objects.
Didn't you see what Randal wrote to you about doing this? If you don't
want to follow his advice, that's your right. But by doing so, you're
implying that you have a good reason for ignoring Randal's suggestions.
> sub RestoreFromFile($){
> my ($filename,$tmp,$VAR1);
> $filename=shift;
> $tmp="";
> open(INFILE, "$filename");
I'm sure that you put those quote marks in there because you wanted to
exercise your typing fingers. So why not get even more exercise by pushing
the backspace key after you typed them? :-) And it sure looks like you're
not checking the return value from open(). Hmmm.
> while(<INFILE>){
> $tmp.=$_;
> }
> eval $tmp;
And you should check the result of $@ after an eval(), too, if you really
must use eval. But what you're doing here looks a lot like the do()
builtin. Right?
> return $VAR1; # returns a reference to an object
> # Why does Data::Dumper format the dump so nicely?
Randal addressed that question in his earlier message. If you've misplaced
it, I could send you a copy. :-)
In the hope that it'll get you back on track, here's the executive summary
of Randal's message:
use Storable;
Happy coding!
--Tom Phoenix
TIMTOWTDI