The Cellar  

Go Back   The Cellar > Main > Technology
FAQ Community Calendar Today's Posts Search

Technology Computing, programming, science, electronics, telecommunications, etc.

Reply
 
Thread Tools Display Modes
Old 04-18-2003, 03:33 PM   #1
That Guy
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.
That Guy is offline   Reply With Quote
Old 04-18-2003, 09:59 PM   #2
dave
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.
  Reply With Quote
Old 04-18-2003, 10:18 PM   #3
SteveDallas
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.
SteveDallas is offline   Reply With Quote
Old 04-18-2003, 10:49 PM   #4
Undertoad
Radical Centrist
 
Join Date: Jan 2001
Location: Cottage of Prussia
Posts: 31,423


Did someone say Pearl?
Undertoad is offline   Reply With Quote
Old 04-19-2003, 07:23 AM   #5
That Guy
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.
That Guy is offline   Reply With Quote
Old 04-21-2003, 01:24 AM   #6
SteveDallas
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.
SteveDallas is offline   Reply With Quote
Old 04-21-2003, 09:59 AM   #7
That Guy
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 {
&nbsp;print header, start_html('test 2'),"\n", start_form,
&nbsp;textfield(-name=>'testvar2', -size=>20),
&nbsp;submit(-name=>'status', -value=>'Third'),"\n",br,
&nbsp;@params;
&nbsp;foreach $param (@params){

&nbsp;print hidden(-name=>$param),

&nbsp;br,$param, "-", param($param),"\n";}
&nbsp;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.
That Guy is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 10:00 AM.


Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.