473,699 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when reading from file

6 New Member
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 1500
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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 Recognized Expert Specialist
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 )=split(/\|/,$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 )=split(/\|/,$account);
Sep 1 '07 #5
numberwhun
3,509 Recognized Expert Moderator Specialist
See, this is why I need to learn more CGI!!! Sorry about that!

Jeff
Sep 1 '07 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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 Recognized Expert Top Contributor
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
2653
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 controls, I get this error. This is how it goes : <code> byte bImage1 = (byte)datasetImageList.Tables.Rows; System.IO.MemoryStream ms = new MemoryStream(bImage1, 0, bImage1.Length); this.lblRunImage.Image = System.Drawing.Image.FromStream(ms); //...
0
1309
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 enable propagation of inheritable permission on child folders. 4.- Read a file using Server.FileSystemObject into the web
0
1285
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 String format, but it is. Any suggestions would be greatly appreciated 'DATAGRID code:
5
4685
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 fileDetails.PostedFile.ContentLength > 0 Then Dim dir As String() = fileDetails.PostedFile.FileName.Split("\".ToCharArray())
0
1198
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, "C:\vb\WebBrowser\WebBrowserControl\TESTFILE.XML", OpenMode.Output) Write(1, "<?xml version=""1.0""?>") The error on top occurs when creating the file. I can see that the
1
1553
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", OpenMode.Output) Write(1, "<?xml version=""1.0""?>") ....
4
2386
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 line. It also works when pulling the options from a file.
1
1568
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 when i run it, it complain, and i don`t know why??? can anyone help me have a look at it? here is the message it complain
6
2776
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 use a string i read from the console Exception in thread "main" java.net.SocketException: Connection r at java.net.SocketInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at...
0
8697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8622
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7761
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.