#!/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.
Yay! I am *such* a bored XP whore... :)#!/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; }
In reply to Re: writing an address book program
by damian1301
in thread writing an address book program
by mexnix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |