Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parsing named parameters

by pg (Canon)
on Nov 07, 2005 at 03:23 UTC ( #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' ] };


Comment on Re: Parsing named parameters
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-08-22 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (148 votes), past polls