As I said earlier, thawing the data was the hard part. Because yours fails if you use strict. By putting in a "print $@" right after the eval, and enabling strict, you'll see:
Not good. The trick? Change your eval line to:Global symbol "$VAR1" requires explicit package name at (eval 1) line +1, <$in> line 1.
We get a lexical "$VAR1" which allows the whole thing to compile. Things don't work so well if you're dumping multiple variables, though. With multiple variables, you either pre-declare all variables using my (or our, or use var), or you split on ;, and put a "my " in front of each variable. The former is dangerous in that you may fail to predeclare some variable, the latter in that a semicolon may show up elsewhere in the data. So it's best to count on a single variable anyway.my $h = eval 'my ' . do { local $/; <$in> };
In reply to Re^2: Need Example of Saving and Retrieving Hash from File
by Tanktalus
in thread Need Example of Saving and Retrieving Hash from File
by EchoAngel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |