in reply to Re: removal of dupes using a hash
in thread removal of dupes using a hash
This is considered a bad thing because Perl will then copy the prematched text and the postmatched text into $` and $' every time it sees a regular expression. This is okay in this kind of example because the data we're dealing with appears to be small. However it rapidly becomes inefficient once we start dealing with longer strings.
A similar, slightly more efficient version can be written:
foreach (@sorted_data) { /(.*?)\.(.*)/; $hash{$1} = $2; } # print hash here by key value - only latest entry exists
It may also be worth wondering why a regular expression is needed at all:
foreach (@sorted_data) { my ($key, $value) = split /\./, $_, 2; $hash{$key} = $value; } # print hash here by key value - only latest entry exists
Hope this helps,
jarich
|
|---|