walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
$db_results{$_} = $1 if $db_results{$_} =~ /(BLAH\d{2}-\w)/ for keys $ +db_results;
Say the hash key is BLAH01-A05AFGH. I want the hash key to be BLAH01-A.
I assume this one is not too hard and that the fellow monks would know how to accomplish it.
UPDATE Sometimes I post a question and 10 minutes later answer it myself...Putting the code here for anyone interested. Probably a better way to do it too, which I'd always be interested in. It's a hash of hashes and it kept my data structure intact, so that's good too.foreach (keys $db_results) { my $match = $1 if $_ =~ /(BLAH\d{2}-\w)/; $db_results->{$1} = delete $db_results->{$_}; + }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replace a hash key if it matches a regex
by AnomalousMonk (Archbishop) on Sep 13, 2013 at 09:54 UTC | |
by walkingthecow (Friar) on Sep 13, 2013 at 10:01 UTC | |
by choroba (Cardinal) on Sep 13, 2013 at 10:14 UTC | |
by walkingthecow (Friar) on Sep 14, 2013 at 03:56 UTC | |
by AnomalousMonk (Archbishop) on Sep 13, 2013 at 10:15 UTC | |
|
Re: Replace a hash key if it matches a regex
by Happy-the-monk (Canon) on Sep 13, 2013 at 08:48 UTC | |
|
Re: Replace a hash key if it matches a regex
by ansh batra (Friar) on Sep 13, 2013 at 08:50 UTC | |
by AnomalousMonk (Archbishop) on Sep 13, 2013 at 09:11 UTC |