Of course CSV would suffice for the example you gave, but it will be a lot more complicated if you have nested structures.

You can combine all the given examples, e.g. use the Database example by using DBD::CSV or next level, tie that CSV database handle with Tie::Hash::DBD and use your hash without changing the rest of your program.

One advice: don't underestimate how "simple" CSV is. *do* use a module, like Text::CSV_XS and/or Text::CSV.

For the hobbies, you would either require a serialization like Sereal or Storable.

If hobbies is the *only* field with multiple values, just drop them at the end of the record, so you can restore them lik

use 5.14.2; use warnings; use Text::CSV_XS "csv"; use Data::Peek; my $data = csv (in => *DATA); my @hdr = @{shift @$data}; my $n = $#hdr; my @students = map { my %h; @h{@hdr} = splice @$_, 0 , $n; $h{hobbies} = [ @$_ ]; \%h, } @$data; DDumper \@students; __END__ name,home_town,age,hobbies Angie Green,Denver,12,Horses,Painting,Karaoke,Ham Radio Jamie Brown,London,34 Mark White,Madrid,56,Cooking,Perl,Running Mary Black,Dublin,30,Baking,Singing,Swimming,Programming Perl

-->

[ { age => '12', hobbies => [ 'Horses', 'Painting', 'Karaoke', 'Ham Radio' ], home_town => 'Denver', name => 'Angie Green' }, { age => '34', hobbies => [], home_town => 'London', name => 'Jamie Brown' }, { age => '56', hobbies => [ 'Cooking', 'Perl', 'Running' ], home_town => 'Madrid', name => 'Mark White' }, { age => '30', hobbies => [ 'Baking', 'Singing', 'Swimming', 'Programming Perl' ], home_town => 'Dublin', name => 'Mary Black' } ]
use Text::CSV_XS "csv";

Enjoy, Have FUN! H.Merijn

In reply to Re^3: Persistent data structures -- why so complicated? by Tux
in thread Persistent data structures -- why so complicated? by davebaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.