in reply to better way delete comma separated hash values?

using a regular expression to search and remove the elements in place could be faster:
my $delete = join('|', map quotemeta, sort @element_to_delete); my $re = qr/(?:^|,)(?:$delete)(?=,|$)/; for (@key_to_search) { if (defined $new_reports{$_}) { $new_reports{$_} =~ s/$re//g; delete $new_reports{$_} unless length $new_reports{$_} } }
updated following ikegami advice

Replies are listed 'Best First'.
Re^2: better way delete comma separated hash values?
by ikegami (Patriarch) on Sep 29, 2008 at 12:16 UTC
    Your regexp is only bounded on one end, but it probably should be bounded on both. Let's not convert "pineapple,apple,banana" into "pinebanana" when deleting "apple".