I think what is meant is that the standard approach is to have your own "hand-coded" module of subroutines for your system, which, in particular, should have two subroutines, say getF and putF, which handle the writing to a file, for example:

sub getF { # warning: untested "dreamware" ... I'll test later and # (if necessary) repost a correction # General routine to read any file into a hash # (key-indexed) whose targets are anonymous hashes # (indexed by your column names) my ( $hashAdr, # reference of hash to write back to - this on +e $fileHandle, # best not to hard-code these around the place # but to have one subroutine per system # that allocates unique ones, which would # therefore get called in the main program $fileName, $fieldDelim, # best use only one per PROJECT # and if in doubt use "$;" $colNamArrAdr, # address of array of the column names - # best to use all upper or all lower case # if possible. $indexPosn # can be e.g. "3" . $; . "4" to say # that the index should be composed of columns # 4 and 5 (surpri-ise!). ) = @_; %$hashAdr = (); # initialise the hash while( <$fileHandle> ) { chop; # you know exactly one <CR> is there. my @cols = split( $fieldDelim, $_ ); my $index = join( "", split( $;, $cols[ $indexPosn ] ) ); # above is designed to handle 1 or more index columns foreach ( @$colNamArrAdr ) { $$hashadr{ $index }{ $_ } = shift( @cols ); } } return; } # the corresponding put routine is obvious from this, but # I'll just mention the important loop: foreach my $key ( sort( keys( %$hashAdr ) ) ) { my @output = (); foreach ( @$colNamArrAdr ) { push( @output, $$hashAdr{ $key }{ $_ } ); } print $fileHandle join( $fileDelim, @output ), "\n"; }

In reply to Re: Re: Re: Hashes/ Simple Database by syman
in thread Hashes/ Simple Database by bmhm

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.