Rance Hall wrote:
> assume the following code:
> 
> my $output = qx{systemcall};
> 
> assume that the output of the systemcall looks something like this
> 
> name\n
> value\n
> name\n
> value\n
> name\n
> value\n
> name\n
> value\n
> name\n
> value\n
> name\n
> value\n
> ...
> 
> what like to do is get the name/value pairs into a hash of some sort
> 
> split wants to split on EACH "\n"
> 
> I think what I need to do is split every other "\n" and then go back and
> split each name\nvalue pair.
> 
> But I'm open to suggestions about HOW to accomplish this.

In list context qx// returns a list and you can assign a list directly to a
hash, for example:

my %hash = qw{ one two three four };

So the only remaining problem is ensuring that the list contains an even
number of items.  If you assume that your data is valid then a simple way to
do what you want would be:


my %hash = qx{systemcall} =~ /.+/g;




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to