If the assignment doesn't allow you to use a module, you might start with dbmopen, which will let you tie a hash variable to a file, and then automatically update the file as you make changes to the hash:

#!/usr/bin/env perl use 5.010; use strict; use warnings; dbmopen(my %h, './database.dbm',0666) or die $!; # open database file $h{mykey} = 'my value'; # save a key/value p +air dbmclose(%h); # close database dbmopen(my %i, './database.dbm',0666) or die $!; # reopen database fi +le say "$_ : $i{$_}" for keys %i; # print key/value pa +irs dbmclose(%i);

When you're comfortable with that, look into tie, which is meant to supersede the dbm* routines and gives you a more flexible way to do the same sort of thing (I think there may be portability issues with dbmopen, which tie was created to alleviate). If you want a database file that's human-readable, you can use something like YAML or JSON on the backend, but those would require a lot of coding or a module.

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.


In reply to Re^6: Some one help me with this code.how to make it work. by aaron_baugher
in thread Some one help me with this code.how to make it work. by yedukondalu

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.