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: Need a Custom or Prewritten Perl Program?: I Need a Programmer for Freelance Work:
plz help imm

 



swathi
New User

Sep 8, 2008, 9:36 AM

Post #1 of 2 (8688 views)
plz help imm Quote | Reply | Private Reply

everythin works somewat fine in my code
but the prob is once the count gets decremented when it is being written in the line it is written with extra new line
plz resolve it

it comes like
seats.txt:
68

67
67

or


seats.txt:
68

67

67

HEY THIS IS MY HTML FILE THAT LEADS TO THE PERL FILE:
<html>
<head>
<title> PURCHASE FORM </title>
</head>
<body>
<pre>
<h3>KINDLY ENTER YOUR DETAILS FOR MBA COUNSELLING </h3>
<form action="http://127.0.0.1/cgi-bin/reg.cgi" method="get" >
<pre> ENTER THE ID: <input type="text" name="id"> </pre>
<br>
<pre>ENTER THE NAME: <input type="text" name="name"></pre>
<br>
<pre>ENTER YOUR ADDRESS: <input type="text" name="add"></pre>

<pre>ENTER YOUR SPECIALISATION CODE: <input type="text" name="code"></pre>

<pre> <input type="submit" value="Submit"></pre>
<TABLE BORDER='2'>
<th>CODE</th>
<th>SPECIALISATION</th>
<tr>
<td>0</td>
<td>finance</td>
</tr>
<tr>
<td>1</td>
<td>hr</td>
</tr>
<tr>
<td>2</td>
<td>economics and statistics</td>
</tr>
</table>
</form>
</body>
</html>

HEY THIS IS MY PERL CODE:

#!C:\Perl\bin\perl.exe

print "Content-type: text/html\n\n";

use CGI qw(param);
print "<b>";
my $name = param("name");
print "Your name is $name\n";
print "<br>";
my $add = param("add");
print "Your address is $add\n";
print "<br>";
my $ran = int(rand(50));

print "Your id no is $ran\n";
print "<br>";
print "PLZ NOTE IT WELL";
print "<br>";




my $code = param("code");
chomp $code;

if ($code eq "0") {
print "Your specialisation is finance";
}

if ($code eq "1") {
print "Your specialisation is hr";
}

if ($code eq "2") {
print "Your specialisation is economics and statistics";
}



print "<br>";
print "</b>";
my $filename = "numbers.txt";

open (my $fh, ">>", $filename) or die "Could not open ’$filename’\n";

print $fh "$ran"."$name"."$code\n";


my $file = "seats.txt";
open(my $fg, "<", $file) or die "Could not open ’$file’\n";
@input = <$fg>;
close $fg;
print (@input);



if ($code eq "0") {
$input[0] = $input[0] -1;
}
if ($code eq "1") {
$input[1] = $input[1] -1;
}
if ($code eq "2") {
$input[2] = $input[2] -1;
}


print (@input);
open(my $fg, ">", $file) or die "Could not open ’$file’\n";
print $fg "$input[0]\n";
print $fg "$input[1]\n";
print $fg "$input[2]\n";


KevinR
Veteran


Sep 8, 2008, 11:59 AM

Post #2 of 2 (8687 views)
Re: [swathi] plz help imm [In reply to] Quote | Reply | Private Reply

This is the wrong forum for your question, but try this:


Code
open(my $fg, "<", $file) or die "Could not open ’$file’\n"; 
@input = <$fg>;
close $fg;
chomp @input;#<-- add this line


Next time post in the Beginners forum.
-------------------------------------------------

 
 


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

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