Gossamer Forum
Home : General : Perl Programming :

I little challenge for you guys !!!

Quote Reply
I little challenge for you guys !!!
I I'm trying to make a big phone book so I've made a script that write the name and the phone number to a data base. it write the name and the phone number like this:
name!phonenumber
(ex:
Nathalie!450-267-3390,
Caroline!450-234-2938,
etc...)

then I have to make a script that give the number to someone else requesting for it . SO I wrote :
#!/usr/bin/perl

########################
#readung the form input#
########################
read(STDIN, $forminput, $ENV{'CONTENT_LENGTH'});
$forminput =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$forminput =~ tr/+/ /;


####################
# reading data file#
####################
open (INFILE, "tel.txt");
@infile = <INFILE>;
close INFILE;

#######################################
#Splitting the @infile into two scalar#
#######################################
@splited = $infile =~ tr/!/,/;

##########################################
#Starting the loops to find the good user#
##########################################
while (@infile){
if ($splited[$i] eq $forminput) {
print "$infile[$i]\n";
}
else ($i){
$i++
}
}
# the else is supposed to increment the array[number]...
#############################
#Printing html header codes #
#############################

print "Content-type:text/html\n\n";
print "<html><head><title>numéro de téléphone</title></head><body>";
#print "@infile\n"; # just a test
#print "$forminput\n"; # just a test
#print "$splited[0] et $splited[1]\n"; # just a test
print "</body></html>";

so how I should really write those codes to do what I need !?

Thanks and have fun...
Quote Reply
Re: I little challenge for you guys !!! In reply to
I assume you are re-creating the wheel to learn Perl, right? This can be done with DBMAN.

Wink

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: I little challenge for you guys !!! In reply to
hehehheheheheheheh ! yeah your right !
Hi Eliot I knew you will answer this post ...

Thanks for the tips ! I will check the DB code, then I'll figure something out !
Quote Reply
Re: I little challenge for you guys !!! In reply to
Thanks Mark,

but in an other post you told me that ''programing in strict was the worst advice to give somebody who's learning perl ''. So I'm learning perl !!! can you please give me the code without strict.

Thanks a lot !
Quote Reply
Re: I little challenge for you guys !!! In reply to
Code:
#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

print header, start_html('numéro de téléphone');

read(STDIN, $forminput, $ENV{'CONTENT_LENGTH'});
$forminput =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$forminput =~ tr/+/ /;

open (INFILE, "tel.txt");
my @infile = <INFILE>;
close INFILE;

foreach (@infile) {
split /!/;
print "$_[0]'s Phone Number is: $_[1]\n" if ($_[0] eq $forminput);
}

print end_html;

--mark
Quote Reply
Re: I little challenge for you guys !!! In reply to
no you misread. In that post I said that the pesron telling someone that they DIDN'T want to bother with programming with strict was the worst advice to give them.

If strict is learned from the beginning it is all the better.

--mark