Hi Folks,
I just ran into a problem that I haven't been able to figure out or find an answer to in the Data::Dumper documentation. I hope a Perl Genius can give me a hand :-).
For quite a long time, for a number of different clients, I've been using Data::Dumper to store different types of hashes of hashes to files. They usually have 3 or 4 levels to them.
They syntax that I've always used to print the hash of hashes to a file (successfully until now) is:
use Data::Dumper;
... open file
print FILE Data::Dumper->Dump([\%hash], [*hash]);
... close file
(where 'hash' is the hash name)
It has always worked flawlessly until yesterday.
With this particular script, running on a Linux system with Perl 6.0, the output replaced the usual hash name header, e.g:
%main::email_addresses = (
... with
$VAR1 = {
It also replaced the closing ); with a };
(That is, replacing the () parens with {} curly brackets and replacing the %hash syntax with $VAR1.
Thus, of course, when I tried to read the hash from the file, it didn't exist as a hash.
My kludgy work around was to replace the $VAR1 and other incorrect elements in the file with the right ones.
I noted in the Data::Dumper documentation the line that stated:
"Any references that are the same as one of those passed in will be named $VARn...".
However, in this case the name of the hash is being replaced. Yet, the hash name is not being duplicated anywhere.
This behavior has never happened to me, and I'm completely puzzled.
I also tried to use the statement:
$Data::Dumper::Sortkeys = 1;
in order to force the keys to sort, but when I did so, the hash was completely wiped out.
Does anyone have any thoughts?
Thank you!
Peter Brown
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.