my @inp = ("abc_A_bla", "abc_B_bla", "abc_C_bla"); my %inp = map { /\w{3}_(\w)/; $1 => $_ } @inp ; foreach ( keys %inp ) { print "$_ => $inp{$_}\n"; }
Update: Better to use bart's version which includes checks for when the regex doesn't match.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re^3: from array to hash with grep
by davorg
in thread from array to hash with grep
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |