On 02/09/2014 05:29 PM, Bill McCormick wrote:
On 2/9/2014 3:58 PM, Shawn H Corey wrote:
On Sun, 09 Feb 2014 10:48:46 -0600
Bill McCormick <wpmccorm...@gmail.com> wrote:

Trying to map the array list into a hash, but loose the double quotes
surrounding the key's value.

You can convert a list to a hash directly:

my %hash = qw( foo1 bar1  foo2 bar2 );


Sure, but that doesn't strip the " and = from this:

my @hash = qw(foo1="bar1" foo2="bar2");

maybe something with a regexp like s/"|=//g?

seems like Perl would have some uber simple way to convert a list of
key="value" elements to a hash.

<untested>

my %hash = map { /(\w+)/g } @array ;

that assumes a word token in the ""

if not, then:

my %hash = map { /(\w+)="([^"]+)"/ } @array ;

in both cases, just grab what you want and ignore the rest.

uri




--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to