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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |