Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: POST and GET

  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts

    POST and GET

    Hi, could someone please explain how post and get data is delt with in perl?
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    I think im on the right track but getting silly error:

    Code:
    for (split /\&/, <STDIN>) {
       (my $key, my $val) = split /=/;
       $val =~ s/\+/ /g;
       $val =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
       my $arg{$key} = $val;
    }
    error
    global symbol $val requires explicit package name


    Any ideas on why?
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,953
    Thanks
    2
    Thanked 172 Times in 167 Posts
    Besides the syntax error on the var assignment, you're using the wrong approach. You should be using the CGI module.
    Code:
    use CGI;
    
    my $cgi = CGI->new;    # handles/processes both GET and POST 
    my %arg = $cgi->Vars;  # Let the module handle the dirty work

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,953
    Thanks
    2
    Thanked 172 Times in 167 Posts
    To answer your question more directly:

    change:
    Code:
    (my $key, my $val) = split /=/;
    to:
    Code:
    my ($key, $val) = split /=/;

  • Users who have thanked FishMonger for this post:

    Phil Jackson (01-28-2010)

  • #5
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    I am not sure why you are getting that error. I made a few minor changes to your code, anyway due to some other minor issues.

    I ran on perl v5.8.8
    Code:
    #!/usr/bin/perl
    use strict;
    
    my %arg;
    for (split /\&/, <STDIN>) {
       my ($key, $val) = split /=/;
       $val =~ s/\+/ /g;
       $val =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
       $arg{$key} = $val;
    }
    
    foreach my $k (keys %arg) {
      print "Key:" . $k . ' Value:' . $arg{$k} . "\n";
    }
    And tested it as such:
    Code:
    $ echo "test=1&hello=5" | ./test2.pl
    Key:test Value:1
    Key:hello Value:5
    However, I would highly recommend that you use the CGI module from CPAN to write any web based app, since it provides the functionality to get all submitted variables. http://search.cpan.org/dist/CGI.pm/l...MED_PARAMETER:

    This module is usually in a default perl installation so you may already have it.
    Whats the point of a signature?

  • Users who have thanked CrzySdrs for this post:

    Phil Jackson (01-28-2010)

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    it was the "my %arg" but going to try the mod as i've read it is better practice for some reason, cheers guys.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •