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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |