On Thu, 2003-10-30 at 16:53, Dan Anderson wrote:
> When I use the following code to dump a hash:
> 
>     $entry{"genre"} = $genre;
>     $entry{"artist"} = $artist;
>     $entry{"album"} = $album;
>     $entry{"disc"} = $disc;
>     $entry{"file"} = $file;
>     $entry{"fullpath"} = $fullpath;
> 
>     my $dumper = Data::Dumper->new( [%entry], [ qw () ] );
>     my $dumpedvalues = $dumper->Dump();
>     print $dumpedvalues . "\n";
> 
> I get the following output:
> 
> $VAR1 = "album";
> $VAR2 = "Prose Combat";
> $VAR3 = "disc";
> $VAR4 = 1;
> $VAR5 = "artist";
> $VAR6 = "MC Solaar";
> $VAR7 = "file";
> $VAR8 = "04_a_la_claire_fontaine.ogg";
> $VAR9 = "genre";
> $VAR10 = "French Rap";
> $VAR11 = "fullpath";
> $VAR12 = "/ogg/French Rap/MC Solaar/Prose
> Combat/04_a_la_claire_fontaine.ogg";
> 
> I've figured out that I can use qw() to change the variable names, but
> is there any way to either get an output like the code that created the
> hash, or in the form:
> 
> $hash = {
>            album => "Prose Combat",
>            # etc...
>         }

Dan,

You're soooo close.....

>From the Camel book Chapter 9 Saving Data Structures shows how to save
hashes to another file.....

Here's what you're example will look like:

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

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'
         );

Hope this helps,
Kevin

-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to