Perl read a line into hash keys and other line into values -
i trying plot stat using external command, , output of external command of 2 lines, like
insert query update delete getmore command flushes mapped vsize *0 961 *0 *0 0 4|0 0 42.2g 85.2g
i trying hash, can later call keys insert/query give corresponding values 0/961 read each line array, as
foreach $line (@qps_raw){ chomp $line; @stats_raw=split("\n ", $line); push (@stats, @stats_raw); print dumper @stats; }
but have no idea how push each element of first line hash keys , each element of second line values. pointers appreciated.
use hash slice:
#!/usr/bin/perl use warnings; use strict; use data::dumper; @names = split ' ', <>; @values = split ' ', <>; %hash; @hash{@names} = @values; print dumper \%hash;
Comments
Post a Comment