Paul Mullen wrote:
> Pádraig Brady wrote:
>> For my sins, I've now to maintain a bit of perl.
>> If I have a `command` that outputs:
>> name1=value1
>> name2=value2
>> How do I init a hash with those names and values?
>> I.E. how do I do the following python in perl?
>>>> command=dict(nv[:-1].split('=') for nv in os.popen("command"))
>>>> cheers,
>> Pádraig.
>>> open F, "command |";
>> my %hash
> while(<F>) {
> my ($name, $value) = split(/=/, $_);
> $hash{$name} = $value;
> }
Thanks for that.
Someone mentioned to me years ago that perl had 'map',
and a quick google confirms it:
http://www.webmasterworld.com/forum13/492.htm
So I'll probably cook something up with that.
cheers,
Pádraig.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!