Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have created the following progra 1

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
US
I have created the following program. In which I create new information in the program and read some data and then write to another file. However, it give me the following error:

String found where operator expected at cardp.cgi line 38, near "OUTF "$countp2|"" (Do you need to predeclare OUTF?) syntax error at cardp.cgi line 38, near "print" Execution of cardp.cgi aborted due to compilation errors. could not fire up cardp.cgi


#!/usr/bin/perl
print "Content-type:text/html\n\n";
#cardp.cgi - use with card.html and card.cgi and cardp.out - Apartment for Rent
open(INF,"cardp.out") or dienice("Couldn't open apart.out for reading: $! \n");
@data = INF
print &quot;<h2>Card Payment</h2>\n&quot;;
# First we initialize some counters and hashes for storing the
# summarized data.
$countp2 =0;
$commentary =&quot;&quot;;

&print_page_start;
$card = $query->param('card');
$number = $query->param('number');
$date = $query->param('date');
$namec = $query->param('namec');

open(OUTF, &quot;<cardc.out&quot;) or dienice(&quot;Couldn't open auto.out for reading: $! \n&quot;);

foreach $i (@data) {
chomp($i);
($name,$address,$city,$state,$zipcode,$location,$photo,$squarefoot,$nofbedroom,
$nofbathroom,$livingroom,$familyroom,$dinningroom,$basement,$deck,
$fireplace,$petallowed,$utility,$askingprice,$security,$deposit,$email,$telephone,$timetocall,$comment1,
$costt,$costp,$pay,$month,$day,$year) = split(/\|/,$i);

# this is the same as $countp2 = $countp2 + 1;


# Reset the file pointer to the end of the file, in case
# someone wrote to it while we waited for the lock...


print OUTF &quot;$FORM {'telephone'}|&quot;;
print OUTF &quot;$FORM{'card'}|&quot;;
print OUTF &quot;$FORM{'number'}|&quot;;
print OUTF &quot;$FORM{'date'}|&quot;;
print OUTF &quot;$FORM{'namec'}|&quot;;
print OUTF &quot;$FORM{'address'}|&quot;;
print OUTF &quot;$FORM{'city'}|&quot;;
print OUTF &quot;$FROM{'state'}|&quot;;
print OUTF &quot;$FORM{'zipcode'}\n&quot;
}

close (OUTF);
close (INF);

sub print_page_start {
print $query->header;
print &quot;<html>\n<head>\n<TITLE>Credit Card Information</TITLE>\n&quot;;
print &quot;</HEAD>\n<BODY>\n&quot;;
print &quot;<FORM>\n&quot;;
print &quot;Name of the card<input type=\&quot;radio\&quot; name=\&quot;card\&quot; value=\&quot;Visa\&quot;>Visa<input type=\&quot;radio\&quot; name=\&quot;card\&quot; value= \&quot;MasterCard\&quot;>Master Card<input type=\&quot;radio\&quot; name=\&quot;card\&quot; value=\&quot;Discover\&quot;>Discover\n<br>&quot;;
print &quot;Card Number<input type=\&quot;text\&quot; name=\&quot;number\&quot;>Number</A>\n<br>&quot;;
print &quot;Expiration Date<input type=\&quot;text\&quot; name=\&quot;date\&quot;>date\n<br>&quot;;
print &quot;Your Name as it appears on the card <input type=\&quot;text\&quot; name=\&quot;namec\&quot;>Name\n<br>&quot;;
print &quot;<INPUT TYPE=\&quot;submit\&quot;><INPUT Type=\&quot;reset\&quot;>\n<br>&quot;;
print &quot;<FORM>\n&quot;;
}

print <<EndHTML;
EndHTML
sub dienice {
my($msg) = @_;
print &quot;<h2>Error</h2>\n&quot;;
print $msg;
exit;
}

I would appreciate any help that you can provide.
 
IT looks like you are missing data, I can not even find a line that refers to $countp.

Maybe you've hacked it up a bit trying to fix it and pasted the wrong version?

 
Hi.
For one thing at this line :
print OUTF &quot;$FORM{'zipcode'}\n&quot;
You forgot to close the line with a semi-colon.

Also too you are trying to write to a file that is open in
Read Only mode.
open(OUTF, &quot;<cardc.out&quot;) Read Only
open(OUTF, &quot;cardc.out&quot;) Read Only
open(OUTF, &quot;>cardc.out&quot;) Write Mode
Warning : Write Mode will *overwrite* existing file
open(OUTF, &quot;>>cardc.out&quot;) Append Mode

And like Siberian pointed out, you are missing the line(s)
that the error is in reference to.
But I suspect your code was something like this :

# this is the same as $countp2 = $countp2 + 1;
$countp2++;
# Reset the file pointer to the end of the file, in case
# someone wrote to it while we waited for the lock...
seek(OUTF,0,2);
## First line of your output
print OUTF &quot;$countp2|&quot;;

One last thing...
near the top of your code you have this line :
@data = INF
It has to be written as
@data = <INF>;
Be careful not to forget the semi-colons.

Hope this helps.

Take Care.
Crackn101
 
Thank you very much for taking your time to explain and suggest ways to fix the problem. I really appreciate your time and help. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top