in reply to populating a HoA with regexp
You could do this:
#! perl -slw use strict; use Data::Dump qw[ pp ]; my %dfs; m[([a-z]+)(\d+)] and push @{ $dfs{ $1 } }, $2 while <DATA>; pp \%dfs; __DATA__ brain0001 lung0001 brain00002 kidney0003 brain00003
Outputs:
[14:52:38.81] C:\test>junk58 { brain => ["0001", "00002", "00003"], kidney => ["0003"], lung => ["0001"], }
But maybe you don't want to load up anything you are not expecting? Maybe you want a warning for lines that don;t match your regex?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: populating a HoA with regexp
by asqwerty (Acolyte) on Aug 28, 2012 at 14:07 UTC |