Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: writing an address book program

by damian1301 (Curate)
on Jun 07, 2001 at 01:09 UTC ( #86396=note: print w/ replies, xml ) Need Help??


in reply to writing an address book program

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


Comment on Re: writing an address book program
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://86396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-10-21 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls