473,774 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New page in perl

74 New Member
Hi. I need to create 3 pages. Page 1 requests the number of elements the user wants to add and average. Page 2 asks the user for the numbers. Page 3 adds and averages the numbers and displays them. I can't create a separate page 3 to do this. Page 3 shows the contents of page 2 in addition to the contents of page 3. How do I get only the contents on page 3 to display separately? Everything works so I'm just asking how to do this. Any feedback would be appreciated. Thanks in advance. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. BEGIN
  4. {
  5.     open(STDERR, ">&STDOUT");
  6.     select(STDERR); $| = 1;
  7.     select(STDOUT); $| = 1;
  8.     print "Content-type: text/html\n\n";
  9. }
  10.  
  11. if($ENV{'QUERY_STRING'} eq "")
  12. {
  13.     &page1;
  14.     exit;
  15. }
  16.  
  17. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  18.  
  19. if($buffer eq "")
  20. {
  21.     $buffer = $ENV{'QUERY_STRING'};
  22. }
  23.  
  24. @pairs = split(/&/, $buffer);
  25. foreach $pair(@pairs)
  26. {
  27.         ($name, $value) = split(/=/, $pair);
  28.  
  29.     $value =~ tr/+/ /;
  30.         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  31.         $name =~ tr/+/ /;
  32.         $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  33.  
  34.     if($FORM{$name} eq "")
  35.     {
  36.         $FORM{$name} = $value;
  37.     }
  38.     else
  39.     {
  40.         $FORM{$name} .= " " . $value;
  41.         #$FORM{$name} /= " " . $value;
  42.  
  43.     }
  44. }
  45.  
  46. $num = $FORM{"num"};
  47.  
  48. sub page1
  49. {
  50. print <<ENDHTML;
  51. <title>Assignment #4 (CS Credit)</title>
  52. <body text="white" bgcolor="blue">
  53. <font face="arial" size="4">
  54. <div align="center">
  55. <form method="get" action="/~westj2/cgi-bin/assignment4_CS_credit.cgi">
  56. <br>
  57.  
  58. Enter the number of elements to add and average:
  59. <input type="text" name="num" value="3"><br><br>
  60. <input type="submit" name="sub" value="Submit">
  61. <input type="reset" name="res" value="Reset">
  62.  
  63. ENDHTML
  64. }
  65.  
  66. print <<ENDHTML;
  67.  
  68. <title>Assignment #4 (CS Credit)</title>
  69. <body text="white" bgcolor="blue">
  70. <font face="arial" size="4">
  71. <div align="center">
  72. <form method="get" action="/~westj2/cgi-bin/assignment4_CS_credit.cgi">
  73.  
  74. Enter elements you want to add and average:<br><br>
  75.  
  76. ENDHTML
  77.  
  78. for($i = 1; $i <= $num; $i++)
  79. {
  80.     print "Element #$i: ";
  81.     print "<input type='text' name=$i value=$i><br>";
  82. }
  83.  
  84.  
  85. print <<ENDHTML;
  86.  
  87. <br><input type="submit" name="calc" value="Submit">
  88. <input type="reset" name="res" value="Reset">
  89. <input type="hidden" name="num" value=$FORM{"num"}>
  90.  
  91. ENDHTML
  92.  
  93. my @queue;
  94.  
  95. for($i = 1; $i <= $num; $i++)
  96. {
  97.     unshift(@queue, $FORM{"$i"});
  98. }
  99.  
  100. my @elements = @queue;
  101.  
  102. print "You entered: ";
  103.  
  104. for($i = 1; $i <= $num; $i++)
  105. {
  106.     print(pop(@queue));
  107.     print " ";
  108. }
  109.  
  110. my $sum;
  111.  
  112. for($i = 0; $i < $num; $i++)
  113. {
  114.     $sum = $sum + @elements[$i];
  115. }
  116.  
  117. print "<br>Sum: $sum";
  118.  
  119. my $avg = $sum / $num;
  120. print "<br>Average: $avg";
  121.  
Jun 3 '09
15 3482
RonB
589 Recognized Expert Moderator Contributor
You know that I know the perfect place.
http://www.rosysattheb each.com

Now, watch me get dinged for the semi self promotion
Jun 5 '09 #11
KevinADC
4,059 Recognized Expert Specialist
hehehe.... maybe one of these days I'll take you up on that. BTW, welcome to bytes.com :)
Jun 6 '09 #12
RonB
589 Recognized Expert Moderator Contributor
@KevinADC
I might even get behind the bar, which usually means I lower their profit margin, so beware. :)

@KevinADC
Thanks,
I'm starting to see the other sites we're on slow down (or I'm just getting bored) so I need to add a few more to my "resume".
Jun 6 '09 #13
KevinADC
4,059 Recognized Expert Specialist
This perl forum used to be hopping. Look at my post count in just a little over two years as a member here. Sure, some of it is not in the perl forum but the majority is. This forum went nearly dead about 6 to 7 months ago when some forum changes were made. Its getting a little activity now but not even close to what it used to be.
Jun 6 '09 #14
NeoPa
32,573 Recognized Expert Moderator MVP
It's great to see you popping back Kevin - if only now and then.

No promises, but we're hoping to have a change (or two) released shortly which may allow the site to grow again (to stop it's further decline at least). Watch this space (but keep the breathing going - I don't have any dates yet).
Jun 7 '09 #15
numberwhun
3,509 Recognized Expert Moderator Specialist
@NeoPa
That is absolutely good to hear. Thanks for the info! :)
Jun 7 '09 #16

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

Similar topics

9
2706
by: william c | last post by:
I don't really know PHP that well. I'm fixing a Perl program that accesses a db after getting form input from a PHP page. If the server-side validation fails I'd like to reload the form with all the user's info still filled in. I could embed the entire page in the Perl program but it seems like there must be a better way to go. Is there a way to get the info into the Post environment variable and add code for the PHP page to read it...
9
2922
by: Andrew DeFaria | last post by:
I have somebody or some people who are abusing a Perl based .cgi script. I have written a PHP page which reports this abuse as per $_SERVER. My intentions were to replace the .cgi script with this .php script. Problem is these people are coming in with some web crawler or something like that (i.e. wget http://myserver.com/thescript.cgi). Now if I replace thescript.cgi with thescript.php they will not hit it. And if I replace thescript.cgi...
2
2540
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # suppose you want to fetch a webpage. from urllib import urlopen print urlopen('http://xahlee.org/Periodic_dosage_dir/_p2/russell-lecture.html').read() # note the line # from <library_name> import <function_name1,function_name2...>
5
1921
by: crunix | last post by:
Hello. I have developed a medical application with php 4 linked to IBM DB2 database. The database connection is right and i can access data with no problem...but sometimes when i reload the page which has been already loaded (by pressing CTRL-R) i receive an SQL STATE Error: "(...) SQL State: X (..)"
6
4901
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
0
1439
by: Thomas Blabb | last post by:
Sorry for this question but how do I write a simple "Hello world" HTML page from a perl script? In other words if I click in an already existing html page on a link like: .... <a href="/export/home/aaa/cgi-bin/writehello.pl" target="_top">Click on this link</A> .... a html page with the following stuff should be written and displayed in the browser:
4
3757
by: benwylie | last post by:
I am running IIS 6.0 on Windows 2003. I would like to be able to run a perl script from a web page and include the output. I have tried doing it with an ssi: <form action='docsearch.shtml' method='get'> <!--#exec cgi="/cgi-bin/docsearch.pl--> </form> This correctly ran the script, but it was unable to include the
0
6497
by: sandy | last post by:
hello,,,,,,,,, i am creating login page using Perl/CGI facing prob... able to connect DB but from there facing prob If u have related code of login page in Perl please send me on sandip.bhosale@gmail.com please help me i am using MySQL as DB user name:root password:root database name:ITS
22
6046
by: owlice | last post by:
Greetings! I thought I'd add a little something to a web site, a "tip of the week," and wanted it automated so that if I get hit by a truck (or, more likely, am forgetful), the tip is updated automatically. I learned enough Perl (read: just enough) to code a script that does what I want it to do. Now the question is: how to get it to run automatically. I would like the program to be invoked when someone, anyone, hits my homepage. I...
0
9621
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
10264
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
10106
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...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2852
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.