![]() |
|
Technology Computing, programming, science, electronics, telecommunications, etc. |
![]() |
|
Thread Tools | Display Modes |
|
![]() |
#1 |
He who reads, sometimes writes.
Join Date: Sep 2001
Location: at the keyboard
Posts: 791
|
Anyone know perl?
I'm working on some web stuff. Anyone know anything about the CGI.pm? This is not a contest, and you will not get anything other than a (possible) thanks from me.
![]() |
![]() |
![]() |
![]() |
#2 |
Guest
Posts: n/a
|
What's the question? My perl books got toasted, but I can buy some more, and it's entirely possible that your question falls in my range of knowledge off the top of my head. I haven't done a whole lot of perl, but I know enough to make myself useful quite often. At least at what <b>I</b> do.
|
![]() |
![]() |
#3 |
Your Bartender
Join Date: Jan 2002
Location: Philly Burbs, PA
Posts: 7,651
|
I'm not an expert, but I've written some simple stuff with CGI.pm. Mostly things like a form to let folks set their .forward file without having to log in and use vi. What are you trying to do?
Oh yeah, and in case you haven't figured out.... if you're trying to do something in perl, it's almost a lock that somebody else already did it. So check for pre-existing modules before you re-invent the wheel. |
![]() |
![]() |
![]() |
#4 |
Radical Centrist
Join Date: Jan 2001
Location: Cottage of Prussia
Posts: 31,423
|
![]() Did someone say Pearl? |
![]() |
![]() |
![]() |
#5 |
He who reads, sometimes writes.
Join Date: Sep 2001
Location: at the keyboard
Posts: 791
|
#!/usr/bin/perl -w
use CGI qw(:standard *table *font); use strict; my @params; my $param; sub first { print header, start_html('test'),"\n",start_form, textfield(-name=>'testvar1', -size=>20), submit(-name=>'status', -value=>'Second'), "\n",br, end_form(), end_html(); } sub second { print header, start_html('test 2'),"\n", start_form, textfield(-name=>'testvar2', -size=>20), submit(-name=>'status', -value=>'Third'),"\n",br, @params; foreach $param (@params){ print br,$param, "-", param($param),"\n";} end_form(), end_html(); } sub third { print header, start_html('test 3'),"\n", @params; foreach $param (@params){ print br,$param, "-", param($param),"\n";} print end_html; } @params=param; first() unless param('status'); if (param('status') =~ "Second") {second();} if (param('status') =~ "Third") {third();} What I'm trying to do is preserve the variables and their values between these different functions. When I move from function 1 to function2, I keep one value, but from 2 to 3, I lose it but retain the second variable. If you have the ability to plug this into your CGI directory, you'll probably understand, otherwise it might not make much sense. If you aren't clear about what I'm trying to accomplish here, let me know, and I'll explain it in detail. Thanks for any help. |
![]() |
![]() |
![]() |
#6 |
Your Bartender
Join Date: Jan 2002
Location: Philly Burbs, PA
Posts: 7,651
|
Don't forget, HTTP is stateless--which means each time your CGI gets hit the browser is entering it "fresh"--except for whatever the browser passes in. The simplest way to maintain the info in between "sessions" is to embed the information you want to keep in your outputted HTML as an input field of type "HIDDEN". So it will be invisible to the casual user, but of course anybody who looks at the page source will see it. You can do a lot with this method if you do not have a big need for security. (If you're using a GET method with the form it will not only be visible in the HTML source, it will show up as part of the URL and in the web server log as well!)
Of course you can encrypt the text you place in the HIDDEN input field. Another way to do this kind of thing is with cookies. |
![]() |
![]() |
![]() |
#7 |
He who reads, sometimes writes.
Join Date: Sep 2001
Location: at the keyboard
Posts: 791
|
Sorry - I forgot to post my fix to this. Here's what I ended up with:
sub second { print header, start_html('test 2'),"\n", start_form, textfield(-name=>'testvar2', -size=>20), submit(-name=>'status', -value=>'Third'),"\n",br, @params; foreach $param (@params){ print hidden(-name=>$param), br,$param, "-", param($param),"\n";} end_form(), end_html(); } Notice the extras line within the foreach. I could have gone with cookies, but I hate having to program with them (verification and all that). Thanks for looking at it, SD. |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|