Exercise: Parse HTTP values



You get one line like the following:
fname=Foo&lname=Bar&phone=123&email=foo@bar.com

Build a hash table from it so:
print $h{fname};      #  Foo 
print $h{lname};      #  Bar
...

Start with this file:


examples/hashes/split_http_skeleton.pl
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
 
my @input = (
    'fname=Foo&lname=Bar&email=foo@bar.com',
    'ip=127.0.0.1&machine=foobar',
);

foreach my $str (@input) {
    process($str);
}

sub process {

    my %data;

    # put your code here

    print Dumper \%data;
}

$VAR1 = {
          'email' => 'foo@bar.com',
          'lname' => 'Bar',
          'fname' => 'Foo'
        };
$VAR1 = {
          'ip' => '127.0.0.1',
          'machine' => 'foobar'
        };