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:
What is a Join?

 



axaflaxar
Novice

Jan 23, 2003, 11:44 AM

Post #1 of 5 (1124 views)
What is a Join? Can't Post

I am trying to do is to open 2 files at once. One is accts.txt where account name, and product orderd goes. The other is resacct.txt. where just the name of the restaurant goes here. This is where I would use a join?

Can someone give me a sample?


BackUp
Novice

Jan 23, 2003, 12:21 PM

Post #2 of 5 (1120 views)
Re: [axaflaxar] What is a Join? [In reply to] Can't Post

It depends what you want to do with the two files. A join() will join two strings together with or without a delimiter, for example:

my $foo = join "::", 1..10;

...would give:

1::2::3::4::5::6::7::8::9::10


davorg
Thaumaturge / Moderator

Jan 24, 2003, 2:03 AM

Post #3 of 5 (1110 views)
Re: [axaflaxar] What is a Join? [In reply to] Can't Post

Can you give us the formats of the two files and the format of the output that you want to get.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


axaflaxar
Novice

Jan 24, 2003, 5:40 AM

Post #4 of 5 (1109 views)
Re: [davorg] What is a Join? [In reply to] Can't Post

Ok. here is the script that will write data to a text file that holds the acct. name, description, and what they ordered. This script as you can see only writes to one file at a time.

What I need is for the script to do is write to 2 textfiles at once. The other textfile I want to write to is called RESACCT.txt. All I need to go in this file is the account name.



#!/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>)~;


Here: This is what the data looks like in the text file. Both textfiles will have the same format or look the same once printed to the textfile.


Service provided on Thursday, January 23, 2003, 20:26:46&
The Account name is 69069BUNGALO BILLIARDS STERLING&
The Description is SERVICE AND COLLECTIONS&
The Items sold are &
&


Service provided on Thursday, January 23, 2003, 20:27:45&
The Account name is 66967 PAOLO'S RESTON&
The Description is SERVICE AND COLLECTIONS&
The Items sold are &
&


Service provided on Thursday, January 23, 2003, 20:29:53&
The Account name is 10497 RIVERBEND CC&
The Description is SERVICE AND COLLECTIONS&
The Items sold are 5 knight squèeze tubes&
&


davorg
Thaumaturge / Moderator

Jan 24, 2003, 6:47 AM

Post #5 of 5 (1105 views)
Re: [axaflaxar] What is a Join? [In reply to] Can't Post

You like making things hard for yourself don't you? Your CGI parameter parser is horrible and buggy. Try something more like this:

Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI ':standard';
use POSIX 'strftime';
use Fcntl ':flock';

print header;

open(TECH, '>>./TEXTFILES/CO2ACCTS.txt')
or die $!;
flock TECH, LOCK_EX or die $!;
open(REST, '>>/path/to/RESACCT.txt')
or die $!;
flock REST, LOCK_EX or die $!;

my $time = strftime '%A, %B %d, %Y %H:%M:%S', localtime;

my $acct = param('ACCOUNT');
my $desc = param('DESCRIPTION');
my $amt = param('AMOUNT');

print TECH <<"END";

Service provided on $time&
The Account name is $acct&
The Description is $desc&
The Items sold are $amt&
&

END
close TECH;

print REST <<"END";
What ever you want to go in to the other file
END
close REST;

print a({-href = > 'http://www.chemtroninc.com/OFFICEINDEX.HTML'},
'OFFICEINDEX.HTML');


I'm still not sure where "joining" comes into it. And the HTML page that you're printing is completely invalid :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


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

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