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' # };
In reply to Re: converting an arbitrary string into a hash based on a pattern
by holli
in thread converting an arbitrary string into a hash based on a pattern
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |