CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Is an array needed here?

 



axaflaxar
Novice

Jan 17, 2003, 11:48 AM

Post #1 of 3 (552 views)
Is an array needed here? Can't Post

I am able to capture data from a form and send it to a text file. What I would like for the PERL Script to do is go through say 100 customer names. IF that customer name is picked I want it to go to that customers particular text file. Ex. Mary places an order. Her info goes to Mary.txt. Joe places an order. His info goes to Joe.txt. Right now I have all customers going to one text file. Do I need an array for something like this; to cycle through a bunch of customer names and send it to that customers file when it is entered in the form? Only Here is my current code for all customers going to 1 text file:


#!/usr/bin/perl
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@gold=split(/&/,$buffer);
foreach $ab (@gold) {
($le,$ri)=split(/=/,$ab);
$ri=~tr/+/ /;
$ri=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$Regis{$le}=$ri;
}
open(TECH,">>./TEXTFILES/CO2ACCTS.txt");
print "Content-type: text/html\n\n";
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday");
@months = ("January","February","March","April","May","June",
"July","August","September","October","November",
"December");
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
$year = $year + 1900;
$timey=$hr;
$timei=$min;
$timee=$sec;
print TECH
"
Service provided on $days[$wday], $months[$mon] $mday, $year, $timey:$timei:$timee&
The Account name is $Regis{ACCOUNT}&
The Description is $Regis{DESCRIPTION}&
The Items sold are $Regis{AMOUNT}&
&
\n";
close(TECH);
print qq ~CLICK HERE(<A href="http://www.chemtroninc.com/OFFICEINDEX.HTML">OFFICEINDEX.HTML</A>)~;


thodi
stranger

Jan 17, 2003, 12:55 PM

Post #2 of 3 (549 views)
Re: [axaflaxar] Is an array needed here? [In reply to] Can't Post

First of all: It's safer to use CGI.pm than fiddling with the query string yourself.

If I understood you correctly, then you don't need an array at all, just write to the file with the username that was given by the parameter. But if you really need to verify that name against a list of costumers, it would be faster to have a hash with the costumer names as keys. That way you could check if the given name is a valid one (like if (exists $costumers{$name}) { ... }).

PS: Just out of curiosity: What are those "&" characters for in the string you print out?


Paul
Enthusiast

Jan 18, 2003, 2:39 AM

Post #3 of 3 (547 views)
Re: [axaflaxar] Is an array needed here? [In reply to] Can't Post

Also use error checking on your open()

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives