Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

data structure

by sara2005 (Scribe)
on Sep 08, 2005 at 11:18 UTC ( [id://490177] : perlquestion . print w/replies, xml ) Need Help??

sara2005 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a text file that has data as shown below:-
Start
varname1=name1
varvalue1=value1
vardesc1=desc1
..
..
End

Start
varname2=name2
varvalue2=value2
vardesc2=desc2
..
..
End
etc
etc

Start
varnameN=nameN
varvalueN=valueN
vardescN=descN
..
..
End

Each variable attributes are defined between "Start" to "End". I need to store that in some data structure and use that to build user interface screens using CGI. Also, I need to keep track of the changes to specific variables as users modify them.

I would appreciate any suggestions from the community

Thanks Sara

Replies are listed 'Best First'.
Re: data structure
by sh1tn (Priest) on Sep 08, 2005 at 11:32 UTC
    You may want to take a look at all Config modules. Or just to parse by hand the config text in HoH structure:
    my @data = <DATA>; my $counter = 0; my $data; for(@data){ if(/^Start/../^End/ && ++$counter){ $data->{$counter}{$1} = $2 if /^(\w+)=(\w+)/ } } use Data::Dumper; die Dumper($data); __END__ output: $VAR1 = { '1' => { 'vardesc2' => 'desc2', 'varvalue2' => 'value2', 'varname2' => 'name2' }, '0' => { 'varname1' => 'name1', 'varvalue1' => 'value1', 'vardesc1' => 'desc1' }, '2' => { 'varnameN' => 'nameN', 'vardescN' => 'descN', 'varvalueN' => 'valueN' } };


Re: data structure
by GrandFather (Saint) on Sep 08, 2005 at 11:32 UTC

    Looks like you need an AoA (array of arrays) or a AoH (array of hashes) depening on how you want to access the various fields.

    You could start by looking at perllol and perldata. When you have a little code to start with and are running into trouble, post another question. You have to do the homework first though.


    Perl is Huffman encoded by design.
Re: data structure
by wfsp (Abbot) on Sep 08, 2005 at 13:02 UTC
    If you go with the AoH plan (mentioned by GrandFather) it would work nicely with HTML::Template for your "user interface".

    One way to keep "track of the changes" would be to use CGI::Session.

    As has been mentioned, write some code and let us know how you get on.

    Good luck!