You could instead use an array of arrays.

use strict; use warnings; use Data::Dumper; my $i = 0; my $line = <DATA>; chomp($line); my $colums = { # hash ref to hold colum numbers map { $_ => $i++ } # map each column to a hash an +d give it the index split(/\|/,$line) # split it on the pipe and sen +d it to map }; print Dumper($colums); my $rows; foreach my $line (<DATA>) { chomp $line; push @$rows, [split(/\|/, $line)]; } print "Record 1: first = " . $rows->[0][$colums->{first}]; __DATA__ title|first|last|room|phone|email Mrs|Linda|Caralo|201|148|she@borg.org Miss|Jean|Androno|317|167|j@alo.com Mr|Steve|Paterman|101|100|steve@net.net

That way you don't reproduce colum information. Prob a better way to do this but here was my whack at it.


___________
Eric Hodges

In reply to Re: Is this a reasonable data structure? by eric256
in thread Is this a reasonable data structure? by Theo

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.