The Cellar

The Cellar (http://cellar.org/index.php)
-   Technology (http://cellar.org/forumdisplay.php?f=7)
-   -   Anyone know perl? (http://cellar.org/showthread.php?t=3201)

That Guy 04-18-2003 03:33 PM

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. :D

dave 04-18-2003 09:59 PM

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.

SteveDallas 04-18-2003 10:18 PM

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.

Undertoad 04-18-2003 10:49 PM

http://cellar.org/2003/pearl2.jpg

Did someone say Pearl?

That Guy 04-19-2003 07:23 AM

#!/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.

SteveDallas 04-21-2003 01:24 AM

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.

That Guy 04-21-2003 09:59 AM

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.


All times are GMT -5. The time now is 04:43 PM.

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