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     [EMAIL PROTECTED]            http://www.waveney.org
Telecoms     [EMAIL PROTECTED]  http://www.WaveneyConsulting.com
Web services [EMAIL PROTECTED]            http://www.wavwebs.com
Independent Telecomms Specialist, ATM expert, Web Analyst & Services

Reply via email to