Make a separate program to write to the text files (hey, Perl is great, right?) delimitered by some special character (~,;;,^, etc.).

In your address book program, make it read from the file that you've already wrote to with the other program and split the lines on that special character.

this is a quick hack:

#!/usr/bin/perl -wT use strict; use Data::Dumper; my $del = '~'; my $file="file.txt"; my %hash; open(DB,"$file") || die "$!"; while(<DB>){ my ($nick,$phone,$name,$cell) = split/$del/; #split on $del. %_ = (nick=>"$nick",phone=>"$phone",name=>"$name",cell=>"$cell"); $hash{$nick}={%_}; } print Data::Dumper->new([\%hash],[qw(hash)])->Indent(2)->Quotekeys(0)- +>Dump; # the above is from the Data::Dumper tutorial on this site.


This works for me and I am not aware of anyother way to do it. I will post the program to write to the file in a little bit. Hope i helped, goodbye

UPDATE: Here is the program to write to the database file.

#!/usr/bin/perl -wT use strict; use CGI qw/param textfield start_form end_form Tr Td table h2 submit/; my $file ="file.txt"; my $del ='~'; my $nick = param('nick'); my $phone= param('phone'); my $name = param('name'); my $cell = param("cell"); #----------- ...I love character classes :) ---- stuff(); if ($nick && $phone && $name && $cell){ $nick =~ s/[^A-Za-z_.]//; $phone =~ s/[^0-9\-]//g; $cell =~ s/[^0-9\-]//g; open(DB,">$file") || die "$! DEAD!"; select DB; print $nick,$del,$phone,$del,$cell; # this or the alternative # print "$nick$del$phone$del$cell"; confusing eh? select STDOUT; print "All done :-)" && exit; close DB; }else{print"<BR><BR>\n Nothing has been submitted to put in the file, +yet."; } sub stuff{ print start_form; print h2({-align=>'center'},"Add to the Bitch Book :)"); print table({-width=>'300'},Tr(Td( "Nickname: "),Td(textfield(-name=>'nick', -override=>1),"\n<BR>")) +, Tr(Td( "Phone Number: "), Td(textfield(-name=>"phone", -override=>1),"\n< +BR>")), Tr(Td( "Name: "), Td(textfield(-name=>"name", -override=>1),"\n<BR>")), Tr(Td( "Cell phone number: "), Td(textfield(-name=>'cell', -override=>1)) +)), submit, end_form; }
Yay! I am *such* a bored XP whore... :)

Tiptoeing up to a Perl hacker.
Dave AKA damian


In reply to Re: writing an address book program by damian1301
in thread writing an address book program by mexnix

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.