neversaint has asked for the wisdom of the Perl Monks concerning the following question:
How can generalize the regex in my code such that it also support the following entries?__DATA__ >r4713.1 |SOURCES={GI=162960844,bw,7184325-7184361} >r4714.1 |SOURCES={GI=162960844,fw,6257219-6257255}
My code:# note that there can me more than two "GI"s inside the {} bracket __DATA__ >r7.1 |SOURCES={GI=162960844,bw,0-4;GI=162960844,bw,9025576-9025608}| >r6.1 |SOURCES={GI=152989753,bw,0-30;GI=152989753,bw,1877925-1877931}|
use Data::Dumper; my %all_entry; while (<DATA>) { chomp; next unless (/^>/); my $line = $_; $line =~ />.*\{GI=(\d+),(\w+),(\d+\-\d+)\}/g; # 'g' doesn't seem to work #print "$line --- $1 $str{$2} $3\n"; push @{ $all_entry{$1}{$2} }, $3; } print Dumper \%all_entry; __DATA__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Generalizing Regex with Multiple Match
by ccn (Vicar) on Nov 25, 2008 at 08:36 UTC | |
|
Re: Generalizing Regex with Multiple Match
by prasadbabu (Prior) on Nov 25, 2008 at 08:51 UTC | |
|
Re: Generalizing Regex with Multiple Match
by shmem (Chancellor) on Nov 25, 2008 at 09:59 UTC |