473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Error when reading from file

6
hi...
i am beginner in perl cgi programming..i am atempting to read from a file....
my cgi script is

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl -wT
  2. #print "content-type: text/html \n\n";
  3. use CGI qw(:standard);
  4. use strict;
  5. print header;
  6. print start_html ("ebanking");
  7.  
  8. my $ne=param('name');
  9. my $pwid=param('pwd');
  10.  
  11. open(FP,"input.txt") or die "cannot open file";  
  12. @raw_data=<DAT>;
  13. close(DAT);
  14.  
  15. foreach $account (@raw_data) {
  16.     chop($account);
  17.     ($w_name, $pswd, $accno, $address, $type, $balance) = split(/\|/,$account);
  18.  
  19.     if (( $ne eq $w_name) and ( $pwid eq $pswd)) {
  20.         print " \nName: $w_name Balance: $balance" ;
  21.     } else {
  22.         print "\n User name and password not match";
  23.     }
  24. }#fore each
  25.  
  26.  print end_html;
  27.  
when the above code is executed using WIN 32 apache it shows an internal error...this is the syntax given in every website....
if i remove the print statements corresponding to cgi and run in command line perl it works perfectly....

please help...
Aug 31 '07 #1
9 1492
numberwhun
3,509 Expert Mod 2GB
To begin with, you do not need the shebang line (#!c:\perl\bin\perl -wT) in Windows perl scripting. It is completely ignored. To use taint mode, I believe when you trigger the script on the command line, you would simply specify "perl -T <scriptname>" to trigger it correctly.

Next, do not use the "-w" switch. It is better to use the "use warnings;" pragma instead of the switch.

As for the following code:
Expand|Select|Wrap|Line Numbers
  1. print header;
  2. print start_html ("ebanking");
  3. print end_html;
  4.  
You should really get into the practice of using either just quotes around the text you wish to print or the proper syntax as shown below for these lines. Also, if you have warnings turned on, then Perl will throw an error regarding the use of unquotted strings and their possible conflict with commands or future reserved words.

Expand|Select|Wrap|Line Numbers
  1. print("header");
  2. print ("start_html","ebanking");
  3. print("end_html");
  4.  
Now, try correcting those minor issues and if you could please provide the error that you are seeing, that would be great as well. We just want to see what it is kicking back at you.

Regards,

Jeff
Aug 31 '07 #2
KevinADC
4,059 Expert 2GB
Actually Jeff, these are functions of the CGI module (in bold):

print header;
print start_html ("ebanking");
print end_html;

so that is proper syntax. Putting quotes around print statements is actually not very proper:


print("header");
print ("start_html","ebanking");
print("end_html");


Just use quotes sans the parenthesis for simple prints. But as noted, the original code was correct so no parenthesis or quotes are needed in this case.
Sep 1 '07 #3
KevinADC
4,059 Expert 2GB
While it is true that Windows ignores the shebang line, apache does not. So using the -T switch should work if apache is being used even on Windows.
Sep 1 '07 #4
KevinADC
4,059 Expert 2GB
While it is true that Windows ignores the shebang line, apache does not. So using the -T switch should work if apache is being used even on Windows.

The problem appears to be the use of "strict" (a good thing) but there are a number of undeclared variables:

@raw_data=<DAT>;
foreach $account (@raw_data)
($w_name,$pswd,$accno,$address,$type,$balance)=spl it(/\|/,$account);


the above three lines need to be changed to:

my
@raw_data=<DAT>;
foreach my $account (@raw_data)
my ($w_name,$pswd,$accno,$address,$type,$balance)=spl it(/\|/,$account);
Sep 1 '07 #5
numberwhun
3,509 Expert Mod 2GB
See, this is why I need to learn more CGI!!! Sorry about that!

Jeff
Sep 1 '07 #6
numberwhun
3,509 Expert Mod 2GB
While it is true that Windows ignores the shebang line, apache does not. So using the -T switch should work if apache is being used even on Windows.
See, that I didn't know. I thought it was completely ignored and not use. I was unaware that Apache still read it. Must keep that bit if information in mind.

Regards,

Jeff
Sep 1 '07 #7
KevinADC
4,059 Expert 2GB
I'll make a CGI programmer of you if it kills me.... err.... wounds me.... errr.... causes me mild discomfort in me gulliver. ;)
Sep 1 '07 #8
numberwhun
3,509 Expert Mod 2GB
I'll make a CGI programmer of you if it kills me.... err.... wounds me.... errr.... causes me mild discomfort in me gulliver. ;)
No worries, it'll only be a flesh wound. ;-)
Sep 1 '07 #9
miller
1,089 Expert 1GB
i am beginner in perl cgi programming..i am atempting to read from a file....
my cgi script is

Expand|Select|Wrap|Line Numbers
  1. open(FP,"input.txt") or die "cannot open file";  
  2. @raw_data=<DAT>;
  3. close(DAT);
  4.  
You're opening the file handle FP, but attempting to read from the handle DAT. Most likely this is a copy and paste error, but that's your most glaring problem.

- Miller
Sep 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: cnu | last post by:
Hi I have to write images(.gif/.bmp/.jpg/.ico), to db and read them. Uploading images to db works fine for me. Reading from db to byte is also ok. But, when I try to display them in my form...
0
by: Pedro Bautista | last post by:
Status: Unsolved and puzzling Steps to reproduce the error: 1.- Delete IUSER from server 2.- Reboot server (OS rebuilds IUSR) 3.- Assign IUSR read and execute permission on web folder and...
0
by: Mo | last post by:
Hi, I'm getting an error: Input string was not in a correct format This happens when I try to sort a column. It seems that the sort event handler claims that the sort expression is not in...
5
by: Nathan Sokalski | last post by:
I am trying to write code to allow my users to upload a file. The code I am using is as follows: Dim upfilename As String = "" If fileDetails.Value <> "" AndAlso...
0
by: reidarT | last post by:
Ugyldig på toppnivået av dokumentet. Feil under behandling av ressursen file:///C:/VB/WebBrowser/WebBrowserControl/TESTFILE... "<?xml version=""1.0""?>","<XMLTest>" ^FileOpen(1,...
1
by: ReidarT | last post by:
The former post was wrong, the lines where concatenated so here it goes again. I am wrriting to a file (XML-format) and using FileOpen(1, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML",...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
1
by: shrimpy | last post by:
hi every one, i am new to python, and coz i want to write a handy command for my linux machine, to find a word in all the files which are under the current folder. the code is half done, but...
6
by: diegoblin | last post by:
hello, i have this issue.Every time i use sockets if i use a "String" as a parameter the connection resets. but if i put the ip address like this "127.0.0.1" it okay. and i got this message if i...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.