in reply to Can this code be optimized further?
Another way.
## I'd personally use qw( ) here, but this is probalby just sample dat +a my @temp = ("a_1","b_1","a_2","a_3","a_4","b_2","a_5","b_3","a_6","b_4 +"); my( @a, @b ); my %arrays; eval qq{\$arrays{ "$_" } = \\\@$_} for qw( a b ); for( @temp ) { die "Invalid prefix on element '$_'\n" unless /^([ab])_(.*)/; push @{ $arrays{ $1 } }, $2; }
Update: Gah, left off a couple of \\ to get a reference in the eval.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can this code be optimized further?
by dragonchild (Archbishop) on Feb 10, 2005 at 14:19 UTC | |
by Fletch (Bishop) on Feb 10, 2005 at 14:26 UTC | |
|
Re^2: Can this code be optimized further?
by Roy Johnson (Monsignor) on Feb 10, 2005 at 15:16 UTC | |
by Fletch (Bishop) on Feb 10, 2005 at 15:34 UTC | |
by Roy Johnson (Monsignor) on Feb 10, 2005 at 16:43 UTC |