in reply to Re: More efficient Data Structure needed
in thread More efficient Data Structure needed
The hash method is definitely preferrable though. Reasons to choose one over the other: a large @m_info will take less memory, a large %m_info will provide much faster lookups than the grep loop. So long as memory is not a constraint, the hash is the better choice as the code is both faster and more readable.my $rx = qr/@{ [ join '|', map "(\Q$_->[0]\E)", @m_info ] }/; for my $record (@data) { if (my @match = $record->[1] =~ $regex) { my ($m) = grep defined $match[$_], 0 .. $#match; $record->[1] = join "_", $m_info[$m]->[3], $m_info[$m]->[1]; } }
Makeshifts last the longest.
|
|---|