in reply to loop split into a hash
In case you want to collect the key-value pairs of all $lines in one hash, you could concat them to one long string and then do the split and hash initialisation once outside of your loops. Something like
my $all_lines = ''; for my $data ( @{$res->{ table } } ) { next unless $data->{ name } and $data->{ attr }; foreach my $line (split /\n/, $data->{ attr } ) { $all_lines .= "$line:"; } print "$data->{ name }\t $data->{ attr }\n\n" ; } chop $all_lines; # remove trailing ":" my %values = split /:/, $all_lines;
This isn't fancy, but gets the job done (and is faster, too, than splitting/assigning lines individually).
|
|---|