10.16. Solution: Parse HTTP values

Example 10-5. examples/hashes/split_http.pl

#!/usr/bin/perl
use strict;
use warnings;
 
my $str = 'fname=Foo&lname=Bar&email=foo@bar.com';
my @pairs = split "&", $str;
my %data;
foreach my $p (@pairs) {
    my ($k, $v) = split "=", $p;
    $data{$k} = $v;
}

use Data::Dumper;
print Dumper \%data;


If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed