perlpal has asked for the wisdom of the Perl Monks concerning the following question:
I need to process the elements of a hash into a string. This so that the string can be used as a named parameter call in a method.
Given below is a sample hash
This needs to be processed into : "description => $description, new-role-name => $new-role-name, role-name => $role-name" The code that i've written :$VAR1 = [ { 'description' => '$description', 'new-role-name' => '$new-role-name', 'role-name' => '$role-name', } ];
gives the outputwhile(my ($param_key, $param_value) = each(%{$args->{parameter_set}})) + { $param_string.= "$param_key => $param_value,"; } print "\n$param_string\n";
"description => $description, new-role-name => $new-role-name, role-na +me => $role-name,"
What's not correct in the output above is the comma at the end of the string.How do i correct this ?
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Transform hash elements into a string
by wfsp (Abbot) on Aug 20, 2010 at 06:48 UTC | |
by FloydATC (Deacon) on Aug 20, 2010 at 11:26 UTC | |
|
Re: Transform hash elements into a string
by Ratazong (Monsignor) on Aug 20, 2010 at 06:39 UTC | |
|
Re: Transform hash elements into a string
by Marshall (Canon) on Aug 20, 2010 at 08:51 UTC | |
|
Re: Transform hash elements into a string
by LanX (Saint) on Aug 20, 2010 at 09:09 UTC | |
|
Re: Transform hash elements into a string
by csebe (Initiate) on Dec 18, 2014 at 11:35 UTC |