(readparse) in perl ,i have no idea about perl programming,pls help me,anybody give m

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuneha
    New Member
    • Oct 2013
    • 1

    (readparse) in perl ,i have no idea about perl programming,pls help me,anybody give m

    Code:
    # ReadParse
    # Reads in GET or POST data, converts it to unescaped text, and puts
    # one key=value in each member of the list "@in"
    # Also creates key/value pairs in %in, using '\0' to separate multiple
    # selections
    
    # If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
    # information is stored there, rather than in $in, @in, and %in.
    
    01: sub ReadParse {
    02:     local (*in) = @_ if @_;
    03:
    04:   local ($i, $loc, $key, $val);
    05:
    06:   # Read in text
    07:   if ($ENV{'REQUEST_METHOD'} eq "GET") {
    08:     $in = $ENV{'QUERY_STRING'};
    09:   } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    10:     read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
    11:   }
    12:
    13:   @in = split(/&/,$in);
    14:
    15:   foreach $i (0 .. $#in) {
    16:     # Convert pluses to spaces
    17:     $in[$i] =~ s/\+/ /g;
    18:
    19:     # Split into key and value.
    20:     ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
    21:
    22:     # Convert %XX from hex numbers to alphanumeric
    23:     $key =~ s/%(..)/pack("c",hex($1))/ge;
    24:     $val =~ s/%(..)/pack("c",hex($1))/ge;
    25:
    26:     # Associate key and value
    27:     $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple
      separator
    28:     $in{$key} .= $val;
    29:
    30:   }
    31:
    32:   return 1; # just for fun
    33: }
    Last edited by Rabbit; Oct 30 '13, 03:38 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    That method of parsing the form submission has been depreciated for more that 10 years.

    Use the CGI module.

    If you want to load the cgi input data into a hash, which is what that sub does, then do this:

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    
    my $cgi = CGI->new;
    my %cgi_params = $cgi->Vars;

    Comment

    Working...