For Programmers: Free Programming Magazines  


Home > Archive > PERL on RISC OS > June 2005 > newbie seeks advice on cgi.pm









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author newbie seeks advice on cgi.pm
Dave Lane

2005-06-08, 9:04 pm


Hi all,

I'm dead new to Perl, but am trying to write a cgi script to
handle results being returned to our server using GET - the data
comes from one of our shockwave apps. As our server is an ancient
RiscPC, I'm assuming that there will be one or two quirks.....

I've managed to get some simple 'hello world' scripts going - but when it
gets down to cgi stuff, it would seem that I need the cgi.pm module.

I'n using !Perl - but having trawled through it, can't seem to locate
a 'cgi.pm'. Soooo, can anyone throw me a clue? Many thanks for
any help.

cheers,

Dave

--

.... Don't eat yellow snow.
rafiq@dreamthought.com

2005-06-08, 9:04 pm


> I'n using !Perl - but having trawled through it, can't seem to locate
> a 'cgi.pm'. Soooo, can anyone throw me a clue? Many thanks for any
> help.
>


Goto search.cpan.org and look for CGI.
CPAN is you friend. A big repository of useful and _never_touch_ modules.
You'll depend on it more and more as you get into the language.

Cheers,

Raf




Richard Proctor

2005-06-08, 9:04 pm

On Tue 03 Jun, Dave Lane wrote:
>
> Hi all,
>
> I'm dead new to Perl, but am trying to write a cgi script to
> handle results being returned to our server using GET - the data
> comes from one of our shockwave apps. As our server is an ancient
> RiscPC, I'm assuming that there will be one or two quirks.....


99% of my CGI works on my RPC as well as on my server.

> I've managed to get some simple 'hello world' scripts going - but when it
> gets down to cgi stuff, it would seem that I need the cgi.pm module.


I only use cgi.pm in one script (its among the 1%)

> I'n using !Perl - but having trawled through it, can't seem to locate a
> 'cgi.pm'. Soooo, can anyone throw me a clue? Many thanks for any help.


I use my own code for handling most cgi... I have it in a file called
common[./]pm which I bring in with a "use common" at the fornt of the scripts
that need it.

The relevant code (among about 20 subroutines now in common) is:

# Use this as a wrapper to open any file - then works for both
# RiscOS and on the unix based server
########################################
#####################################
# Mangle filenames to suite RiscOs and Unix #
########################################
#####################################

sub FNMangle {
my $Name = shift;
return $Name if ($Name =~ /^ADFS::/);
$Name =~ s/\.[^.]{0,8}$// if ($flags =~ /R/);
if ($flags =~ /P/) {
};
return $Name;
}

# The main code at the front of your script call this and it handles
# input via parameters, cgi parameters and cookies and dumps them all
# in the hash FORM

########################################
#####################################
# Split and process the buffers #
########################################
#####################################
sub CGI_Decode {
my ($name,$value,@more,@pairs);
my $pair;
my $buffer = "";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}) if ($ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach (@ARGV) {
@more = split(/&/);
push(@pairs,@more);
}

if ($ENV{'QUERY_STRING'}) {
@more = split(/&/,$ENV{'QUERY_STRING'});
push(@pairs,@more);
};

if ($ENV{'HTTP_COOKIE'}) {
while ($ENV{'HTTP_COOKIE'} =~ /(\w*=[^\s;\n]+)(;|)/gi) {
$pair = $1;
($name, $value) = split(/=/, $pair);
unshift (@pairs,$pair);
};
};

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair,2);

$FORM{uc($name)} = 1, next unless defined $value;
# Un-Webify plus signs and %-encoding unless name has a %
unless ($name =~ s/\%// ) {
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\&/&/g;
$value =~ s/\</&lt;/g;
$value =~ s/\>/&gt;/g;
$value =~ s/\r//g;
};
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if (length($name) == 1) {
if ($FORM{$name}) {$FORM{uc($name)} .= "\0$value" }
else { $FORM{uc($name)} = $value };
}
else { $FORM{uc($name)} = $value };
}

if ($FORM{'FLAGS'}) { $flags = $FORM{'FLAGS'};
elsif ($^O eq 'riscos') { $flags = "R" }
else { $flags = "" };

}

# Use this to ensure you have an appropriate http header,

########################################
#####################################
# Http header #
########################################
#####################################
my $Http_Head_Done;

sub Http_Header {
print "Content-type: text/html\n\n" unless $Http_Head_Done++;
}

I then just write the html as I go from the program. Its fast easy to use
and works as I say in 99.99% of cases - the only time I used cgi.pm was
to handle file uploads (which CGI_Decode does not)

Richard


--
Personal Richard@waveney.org http://www.waveney.org
Telecoms Richard@WaveneyConsulting.com http://www.WaveneyConsulting.com
Web services Richard@wavwebs.com http://www.wavwebs.com
Independent Telecomms Specialist, ATM expert, Web Analyst & Services

Roger Horne

2005-06-08, 9:04 pm

On Tue 03 Jun, Dave Lane wrote:

> I'n using !Perl - but having trawled through it, can't seem to locate
> a 'cgi.pm'.


It should be included but (like a lot of things) I don't think it is.
Anywhay, the latest and brightest version will always be found by searching
http://search.cpan.org


Roger
--
Roger Horne
http://www.hrothgar.co.uk/

Dave Lane

2005-06-08, 9:04 pm




just to say thanks all for the tips...will no doubt be back to
ask for more!

cheers,

Dave


In message <Marcel-1.53-0603154935-965Wr#W@hrothgar.hereot>
Roger Horne <roger@hrothgar.co.uk> wrote:

> On Tue 03 Jun, Dave Lane wrote:
>
>
> It should be included but (like a lot of things) I don't think it is.
> Anywhay, the latest and brightest version will always be found by searching
> http://search.cpan.org
>
>
> Roger


--
Literacy Support Software from:
Xavier Educational Software Ltd
School of Psychology, University of Wales Bangor
http://xavier.bangor.ac.uk/

.... I know so little, but I know it fluently...
Nicholas Clark

2005-06-08, 9:04 pm

On Tue, Jun 03, 2003 at 04:49:35PM +0100, Roger Horne wrote:
> On Tue 03 Jun, Dave Lane wrote:
>
>
> It should be included but (like a lot of things) I don't think it is.


It is. For 77 file-per-dir reasons (and case sensitivity) most of the library
is zipped up as !Perl/lib/zip
It's also quite deliberate that that file is not filetype DDC (Archive)
[if you have SparkFS or suchlike then setting it to DDC will work, but I
think that it will be marginally slower]

I believe that all of this is in the documentation.

> Anywhay, the latest and brightest version will always be found by searching
> http://search.cpan.org


Using a newer version is probably a good idea.

Nicholas Clark
James Taylor

2005-06-08, 9:04 pm

On Tue 03 Jun, rafiq@dreamthought.com wrote:
>
> Goto search.cpan.org and look for CGI.
> CPAN is you friend.


Much to my frustration, I find that CPAN modules rarely
just install and work on RISC OS. Many require a compilation
step which I cannot get to work. Even those that do not require
compilation seem to have failings.

For instance, I had been successfully using HTML::Template
for both CGI applications and whole site generation offline.
Sadly, about a year ago, one of the updates broke the module
on RISC OS. This may have had something to do with its
reliance upon File::Spec which doesn't appear to work
correctly on RISC OS, although I never delved any deeper.
Instead, I just stuck with the earlier version, warts and all.
In my experience, the only sure way of getting bug-free code
is to write it myself. I therefore tend to be wary of using
other people's code.

My point is that it is not wise to rely on modules that are
created and maintained by people who have no knowledge of
the limitations of our platform. This is especially true
when so many modules require other modules in a web of
dependencies. If any of those dependencies change, or any of
those modules require compilation, or introduce a bug, or
start using Perl 5.6 features, etc, then the whole web of
modules suddenly fails to work on RISC OS. It might take you
quite a while to trigger those bugs, and unless you want to
go through the code of all the involved modules looking for
the problem, you're stuck. Don't expect the much lauded
cooperative Perl community to notice and correct such
problems. These module maintainers don't test on RISC OS
and, quite frankly, they are unlikely to care.

Given that we're very much on our own in using RISC OS,
I advise being self-reliant and not reliant upon CPAN.

> A big repository of useful and _never_touch_ modules.


You're absolutely right, never touch them!
Write your own code, it's the only way to be sure.

--
James Taylor, Cheltenham, Gloucestershire, UK. PGP key: 3FBE1BF9

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com