*BSD News Article 93301


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!uunet!in3.uu.net!142.77.1.4!news.uunet.ca!not-for-mail
From: "James Leutri" <james@club-webb.com>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: perl script help
Date: Thu, 10 Apr 1997 15:35:33 -0400
Organization: Club-Webb Inc.
Lines: 65
Message-ID: <5ijf34$b4r$1@nntp1.uunet.ca>
NNTP-Posting-Host: main.club-webb.com
X-Newsreader: Microsoft Outlook Express 4.71.0544.0
X-MimeOLE: Produced By Microsoft MimeOLE Engine V4.71.0544.0
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:38876

If somone could explain why this script will not execute the command on
line 5 it would be greatly appreciated.
 Or if there is something else wrong? :).


--- perl script begins ---
#!/usr/bin/perl
print "Content-type: text/html\n\n";
&ReadParse;

open(OUT, "| glimpse -l -y $in{'string'}");
@result = <OUT>;
close(OUT);

$count = 0;

print "<html><head><title>Search Results for \"$in{'string'}\"</title></head
>\n<body bgcolor=#ffffff><H1>Search Results</H1><BR>\n";

for($count =0; $count < @result; $count++)
{ print "Here it is: $result[$count]<BR>\n";
}

print "\n</body></html>\n";

sub ReadParse {
  if (@_) {
    local (*in) = @_;
  }

  local ($i, $loc, $key, $val);

  # Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
      $in .= getc;
    }
  }

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Convert %XX from hex numbers to alphanumeric
    $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Split into key and value.
    $loc = index($in[$i],"=");
    $key = substr($in[$i],0,$loc);
    $val = substr($in[$i],$loc+1);
    $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple
separator
    $in{$key} .= $val;
  }

  return 1; # just for fun
}