How to clear up blanks when converting an array to a hash
Hello, I run an executable that returns a small array of data. my @ans = qx {myexec}; @ans contains the values, Value= 1 Status = 13 Options = 0x0a Quality = 3 I use a map function to convert this array into a hash. my %results = map {(split /=/)} @ans; My questions are: 1. How to I get rid of the blanks on either side of the key and the value? 2. How do I also get rid of the CRLF in the value? I want to be able to reference my hash using something like if ($results{Status} == 9) { print value, $results{Value}, is good; } I may have a syntax error question too: i.e. do I need to double quote the key? e.g. if ($results{Status} == 9) Any help would be greatly appreciated. Thank you. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to clear up blanks when converting an array to a hash
At 04:22 PM 3/21/2006 -0700, Paul Rousseau wrote: @ans contains the values, Value= 1 Status = 13 Options = 0x0a Quality = 3 my %results = map {(split /=/)} @ans; My questions are: 1. How to I get rid of the blanks on either side of the key and the value? 2. How do I also get rid of the CRLF in the value? All u have to do chomp @ans and then change the split to split /\s*=\s*/. That will get rid of the spaces in the return value and also cover the possibility that there are no spaces in the arguments. -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: How to clear up blanks when converting an array to a hash
Chris Wagner wrote: At 04:22 PM 3/21/2006 -0700, Paul Rousseau wrote: @ans contains the values, Value= 1 Status = 13 Options = 0x0a Quality = 3 my %results = map {(split /=/)} @ans; My questions are: 1. How to I get rid of the blanks on either side of the key and the value? 2. How do I also get rid of the CRLF in the value? All u have to do chomp @ans and then change the split to split /\s*=\s*/. That will get rid of the spaces in the return value and also cover the possibility that there are no spaces in the arguments. That covers everything but the first keyword - you may have to deblank that one manually. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs