473,378 Members | 1,434 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,378 software developers and data experts.

CGI script input

11
hi
i HAVE WRITTEN A perl script that will search a file and print output I have created a simple html doc i want to be able to click a link and it will print the output in of a specific file so i need the perl script to read a file 1-15 depending on the input from the html

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl.exe
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. print <<HTTPHDR;
  7. Content-type: text/html
  8.  
  9. HTTPHDR
  10.  
  11. print <<HEADER;
  12. <HTML>
  13. <HEAD>
  14. <TITLE>NAS Disk</TITLE>
  15. </HEAD>
  16. HEADER
  17.  
  18. #print <<OPENBODY;
  19. #<BODY><H2>Nas Disk capacity</H2>
  20. #<PRE>
  21. #OPENBODY
  22.  
  23. my $data_file = 'nas02.txt';####there is fifteen of these 
  24.  
  25. open DATA, "$data_file" or die "can't open $data_file $!";
  26. my @read_data = <DATA>;
  27. my @array_of_data = map { SpecialChars($_); } @read_data;
  28. close DATA;
  29.  
it would be great if some one could tell me what to search for in google so i click on a link 1 to 15 and the perl script has to know what file to read 1 to15 depending on input from html
Aug 28 '07 #1
3 1686
numberwhun
3,509 Expert Mod 2GB
First, always put your code in code tags. It neatens things up and makes it so our wonderful moderators don't have to clean up behind you.

Second, you REALLY need to use punctuation. This isn't text messaging and it would really make your post much clearer.

Speaking of clearer, can you possibly re-word your request for help? At this time I (and possibly others) have absolutely no idea exactly what you are asking for.

Please repost with a better, clearer explanation.

Regards,

Jeff
Aug 28 '07 #2
KevinADC
4,059 Expert 2GB
Use the CGI module to get the input from the form and plug it into a variable:


use CGI qw/:standard/;

my $input_file = param('file_num');

where 'file_num' is the name of the form field that sends the number (1-15) to your script.
Aug 28 '07 #3
markoj
11
Hi folks back again this is the first time i have written a script of any description and I think my difficulty is not understanding some of the answers and cannot use them correctly
1. I have a html page with 15 links each link is linked to one perl script
2. Each link corresponds to a server.
3. When I click on a link I have it directly linked to my perl script
4.so my perl script needs to know what log file to open and read depending on what link I click this is what i cannot get done. how do i do this
5. The nas01.txt is the log file and there are 15 of these
6. Do i put the path of all 15 log files into an array and then use an if statement i.e. if this link is clicked do this or is it something simpler

Any help would be appreciated

Here is my code so far

Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl.exe
  2.  
  3. use warnings;
  4. use strict;
  5. use CGI qw/:standard/;
  6.  
  7.  
  8. print <<HTTPHDR;
  9. Content-type: text/html
  10. HTTPHDR
  11. print <<HEADER;
  12. <HTML>
  13. <HEAD>
  14. <TITLE>NAS Disk</TITLE>
  15. </HEAD>
  16. HEADER
  17.  
  18. my $data_file = "nas01.txt";
  19.  
  20. open DATA, "$data_file" or die "can't open $data_file $!";
  21. my @read_data = <DATA>;
  22. my @array_of_data = map { SpecialChars($_); } @read_data;
  23. close DATA;
  24.  
  25.  
  26.  
  27. foreach my $line ( @array_of_data ) {
  28.     if ($line =~ m/levels/i) {
  29.         print "$line\n\n\n";
  30.  
  31.     } elsif ($line =~ m/date/i) {
  32.         print "$line\n\n\n";
  33.  
  34.     } elsif ($line =~ m/hostname/i) {
  35.         print "$line\n\n\n";
  36.  
  37.     } elsif ($line =~ m/uptime/i) {
  38.         print "$line\n\n\n";
  39.     }
  40. }
  41.  
  42. print "========================================================================================================<br>\n";
  43.  
  44.  
  45. print "</PRE>\n";
  46.  
  47. print "<TABLE border=1>\n";
  48. my $disk = 0;
  49. foreach my $lines ( @array_of_data ) {
  50.     if ($lines =~ m/(\d+)[%]/i) {
  51.     my $val = $1;
  52.     if ($val > 80) {
  53.     $disk++;
  54.     print <<DISK;
  55. <tr style="color: red"><td><PRE>$lines</PRE></td><th>Please look at this disk immediately.</TH></TR>
  56. DISK
  57.  
  58.         } else {
  59.             print <<OKDISK;
  60. <tr style="color: indigo"><td><PRE>$lines</PRE></td><th>Disk levels are ok.</th></tr>
  61. OKDISK
  62.         }
  63.     }
  64. }
  65.  
  66. if ($disk == 0) { print <<ALLDISKOK; <TR style="color:
  67.     green"><TH colspan=2>Disk levels are ok.</th>
  68.     </tr> ALLDISKOK } print "</TABLE>\n";
  69.  
  70. print <<HTMLFOOT;
  71. </BODY>
  72. </HTML>
  73. HTMLFOOT
  74.  
  75. # Remove special chars from input
  76. sub SpecialChars($) {
  77. my ($line) = @_;
  78.     $line =~ s/&/&amp;/sg;     
  79.     $line =~ s/</&lt;/sg;
  80.     $line =~ s/>/&gt;/sg;
  81.     return($line);
  82. }
  83.  
  84.  
Aug 31 '07 #4

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

Similar topics

1
by: Wayne Deleersnyder | last post by:
Hi, I'm a newbie at Perl and CGI and hoping someone can point me in the right direction. Recently I've been going through an older book I have on CGI programming to get a start. Most of it...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
6
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
5
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible....
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
24
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the...
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
7
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under...
11
by: sshade25 | last post by:
I am trying to insert some data into my postgresql database table using an html form and a php script. The problem here is that when the script is run, it does not insert data into the last two...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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.