thank you all for your help-- Broquaint -- I am using the 'do' command as you suggested, but when I try to retrieve a value, it comes out empty. I think the problems is that is doesn't recongnise the %dict hash. I tried using %VAR and it didn't work either.

Any suggestions?

## testing to see if the 'do' command worked: my $dict = do "a.pl" or die "could not load for reading: $!, $@"; my $test = $VAR{anode}{def}; print "test: $test\n";

--------------------------------------

I am without my perl books (I'm not in the US right now) and I can't seem to find any good example of creating a hash, 'dumping' it to a file and then reading the hash in a completely separate program and accessing the values of the original hash.

I've found tons of examples of creating hashes and dumping them (and i was successfully able to do it) -- but I'm having so much trouble using it in a different program. What's the point of dumping all this data to a file if I can't use it quickly and efficiently in a different program?(!)

In my first program I created a hash and wrote it to a file (see below) -- it successfully writes the hash to a file. Can someone help me 'load' this data into a completely different program?

Also, I am creating one file for each letter of the alphabet, but when I load the data in my new program I would like the entire alphabet to be loaded as one hash. Is this possible?:

########################### use Data::Dumper; $Data::Dumper::Purity = 1; my @alph = ('a'..'z'); my $hw; my $def; my $pos; for ($a=0; $a < 1; $a++) ## only doing one letter ## until we get dumper ## to work properly #for ($a=0; $a < @alph; $a++) { $cidefile = "cide.".$alph[$a]; ## the file we're reading from $newfilename = $alph[$a] . ".pl"; open(C,$cidefile) || die "\ncould not open $cidefile for reading\n"; open (N,">$newfilename") || die "could not open $newfilename\n"; @file = <C>; close(C); for ($i=0; $i < @file; $i++) { if ($file[$i] =~ /<hw>(.+?)<\/hw>/) { $hw = lc($1); $hw =~ s/\*|\"|\'|\`//gi; if ($file[$i] =~ /<def>(.+?)<\/def>/) { $def = $1; $def =~ s/<.*?>//g; } if ($file[$i] =~ /<pos>(.+?)<\/pos>/) { { $pos = $1; } ## save the part of speech and the definition $dict{$hw}{pos} = $pos; $dict{$hw}{def} = $def; } } print N Data::Dumper->Dump([%dict],['dict']); close(N); }

In reply to Data Dumper Examples by cranberry13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.