Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Parsing named parameters

by pg (Canon)
on Nov 07, 2005 at 03:23 UTC ( [id://506219]=note: print w/replies, xml ) Need Help??


in reply to Parsing named parameters

Another way:

use Data::Dumper; use strict; use warnings; my $params = "option1 = value0 value1 value2 option3 =value3 value4 op +tion2=value5"; $params =~ s/\s*=\s*/=/g; my @params = split /\s+/, $params; my %params; my $cur_val; for my $param (@params) { my @pairs = split /=/, $param; $cur_val = $pairs[0] if ($#pairs) ; push @{$params{$cur_val}}, $pairs[-1]; } print Dumper(\%params);

Which gives:

$VAR1 = { 'option1' => [ 'value0', 'value1', 'value2' ], 'option3' => [ 'value3', 'value4' ], 'option2' => [ 'value5' ] };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://506219]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found