in reply to Re: Reading from a flat text file database and storing contents in a hash
in thread Reading from a flat text file database and storing contents in a hash

Thanks for your help guys. In giving more thought to the problem, what I want to do is not hand edit the flat text file, but rather build an admin menu, so I can enter new services when needed. Also I wanted to get rid of the hash at the beginning of my program, which has the services in it and having to update it by hand. Instead I wanted to populate the hash with whatever is in the flat text file Does anybody know how I can do this?
  • Comment on Re^2: Reading from a flat text file database and storing contents in a hash

Replies are listed 'Best First'.
Re^3: Reading from a flat text file database and storing contents in a hash
by GrandFather (Saint) on Apr 20, 2007 at 12:38 UTC

    If the number of entries (for whatever definition of entry) is modest then using Data::Dump::Streamer is likely to be as good as anything. If you anticipate a large number of entries then it's probably worth finding out about DBI and the various DBD drivers that allow you to use a "real" data base.

    However, for the simple case consider:

    use strict; use warnings; use Data::Dump::Streamer; my %services = ( 1 => { name => "service1", host => { host1 => 1 }, }, 2 => { name => "service2", host => { host0 => 2, host5 => 2 }, }, ); Dump (\%services); open TEMP, '>', 'temp.txt'; print TEMP Dump (\%services)->Out (); close TEMP; my $newServices = do 'temp.txt'; Dump ($newServices);

    Prints:

    $HASH1 = { 1 => { host => { host1 => 1 }, name => 'service1' }, 2 => { host => { host0 => 2, host5 => 2 }, name => 'service2' } }; $HASH1 = { 1 => { host => { host1 => 1 }, name => 'service1' }, 2 => { host => { host0 => 2, host5 => 2 }, name => 'service2' } };

    DWIM is Perl's answer to Gödel
Re^3: Reading from a flat text file database and storing contents in a hash
by wishartz (Beadle) on Apr 20, 2007 at 12:36 UTC
    I've just looked into XML::Simple as suggested and I can see how I can achieve what I wanted the program to do. Thanks guys.