http://www.perlmonks.org?node_id=1021564


in reply to What would be the easier way

I would do it this way:
use Modern::Perl; use Data::Dump qw/dump/; my %heights; while (<DATA>) { push @{$heights{$1}}, $3 if /set\s+height\s+"([^"]+)"\s*("([^"]+)" +)?/; } say dump(%heights); __DATA__ set height "house" set height "house" "5 meter" set height "house" "10 yards" set height "table" "80 cm" set height "table" "30 inch"
Output:
( "house", [undef, "5 meter", "10 yards"], "table", ["80 cm", "30 inch"], )

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics