Just be aware that require only loads the file the first time you call it. If you need to load up the hash more than once, %{ require 'hash.pl' }; may not be such a good idea. The second time you call it, require sees that the file is already loaded and will return 1, which isn't a hash reference at all. If you have strict or warnings turned on (and you should), Perl will kindly inform you of the problem by generating a warning:Can't use string ("1") as a HASH ref while "strict refs" in use at ....
If you really want to load a file full of Perl code and set a variable in one step, use do instead. Like require it returns the value of the final statement in the file, but it doesn't have the reload problem. This can be safely reused:
%{do 'hash.pl'}Best, beth
In reply to Re^3: Dumping hash of hashes to file and back
by ELISHEVA
in thread Dumping hash of hashes to file and back
by vit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |