On Thu, 2003-10-30 at 18:09, Kevin Pfeiffer wrote: > In article <[EMAIL PROTECTED]>, Kevin Old > wrote: > [...] > > my %entry; > > > > $entry{"genre"} = "Rock"; > > $entry{"artist"} = "3 Doors Down"; > > $entry{"album"} = "Away from the Sun"; > > $entry{"disc"} = "Away from the Sun"; > > $entry{"file"} = "3dd.mp3"; > > $entry{"fullpath"} = "/mp3s/3dd"; > > $Data::Dumper::Purity = 1; > > print Data::Dumper->Dump( [\%entry], [ '*entry' ] ); > > #my $dumpedvalues = $dumper->Dump(); > > #print $dumpedvalues . "\n"; > > > > > > ***OUTPUT*** > > > > %entry = ( > > 'album' => 'Away from the Sun', > > 'artist' => '3 Doors Down', > > 'fullpath' => '/mp3s/3dd', > > 'file' => '3dd.mp3', > > 'disc' => 'Away from the Sun', > > 'genre' => 'Rock' > > ); > > > > Hi Kevin, > > This was interesting! I see what the difference is between your example and > "Dumper(\%entry)", but I wish I also understood what the man page says > about this: > > <man Data::Dumper> > In the extended usage form, the references to be dumped can be given > user-specified names. If a name begins with a "*", the output will > describe the dereferenced type of the supplied reference for hashes and > arrays, and coderefs. > </man> > > The 1st sentence I understand, but not "the dereferenced type of the > supplied reference." > > I just tried this without the asterisk and get "$entry" instead of "%entry" > (or "$VAR1" using the plain procedure). > > So in plain(er) English that means: if the name begins with an "*", the > output type will match that of the referenced variable"? > > -K > -- > Kevin Pfeiffer
Kevin, Yeah, I guess that's it. I'm not really sure how it works (yet), but I got it from Programming Perl. Here's that whole subsection: 9.7 Saving Data Structures If you want to save your data structures for use by another program later, there are many ways to do it. The easiest way is to use Perl's Data::Dumper module, which turns a (possibly self-referential) data structure into a string that can be saved externally and later reconstituted with eval or do. use Data::Dumper; $Data::Dumper::Purity = 1; # since %TV is self-referential open (FILE, "> tvinfo.perldata") or die "can't open tvinfo: $!"; print FILE Data::Dumper->Dump([\%TV], ['*TV']); close FILE or die "can't close tvinfo: $!"; A separate program (or the same program) can then read in the file later: open (FILE, "< tvinfo.perldata") or die "can't open tvinfo: $!"; undef $/; # read in file all at once eval <FILE>; # recreate %TV die "can't recreate tv data from tvinfo.perldata: $@" if $@; close FILE or die "can't close tvinfo: $!"; print $TV{simpsons}{members}[2]{age}; or simply: do "tvinfo.perldata" or die "can't recreate tvinfo: $! $@"; print $TV{simpsons}{members}[2]{age}; Many other solutions are available, with storage formats ranging from packed binary (very fast) to XML (very interoperable). Check out a CPAN mirror near you today! Maybe one of the Perl Gods can explain it....hope this helps, though. Kevin -- Kevin Old <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]