in reply to converting an arbitrary string into a hash based on a pattern
use strict; use Data::Dumper; my %hash; $_="ABCD----[this] fgab [that] BFTE-- [other] AB CD EF---- [foo]"; while ( /\G\s*([\w ]+)[\s-]+\[(\w+)\]/g ) { $hash{$1}=$2; } print Dumper (\%hash); #$VAR1 = { # 'fgab ' => 'that', # 'ABCD' => 'this', # 'BFTE' => 'other', # 'AB CD EF' => 'foo' # };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: converting an arbitrary string into a hash based on a pattern
by Anonymous Monk on Mar 04, 2005 at 04:55 UTC | |
by lidden (Curate) on Mar 04, 2005 at 05:00 UTC |