seaver has asked for the wisdom of the Perl Monks concerning the following question:
My question is, is this the only way I could get through the variable number of groups? I feel like I could write it into the regular expression itself, that the variable number of groups get directly inserted into an array or a hash, and I can exclude the while loop...is this possible?perl -ne 'chomp;split /\s+/,$_;print $_[1],"\n";while($_[1] =~ /([A-Z +][a-z]?(\d*))/g){print "\t",$1,"\t",$2,"\n";}'
__DATA__ CH4N2O C9H12N2O6 C5H11NO2 C5H4N4O2 C10H11N4O9P C10H12N4O6 C5H10O5 C5H12O5 C5H10O5 C27H44O C1694H2993O101
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive capture of a variable number of elements using regexp
by kennethk (Abbot) on Apr 09, 2009 at 17:58 UTC | |
by jwkrahn (Abbot) on Apr 09, 2009 at 18:31 UTC | |
by linuxer (Curate) on Apr 09, 2009 at 18:47 UTC | |
by kennethk (Abbot) on Apr 09, 2009 at 19:23 UTC | |
by seaver (Pilgrim) on Apr 09, 2009 at 18:08 UTC | |
|
Re: Recursive capture of a variable number of elements using regexp
by BrowserUk (Patriarch) on Apr 09, 2009 at 18:08 UTC | |
|
Re: Recursive capture of a variable number of elements using regexp
by jwkrahn (Abbot) on Apr 09, 2009 at 18:11 UTC | |
by AnomalousMonk (Archbishop) on Apr 10, 2009 at 01:58 UTC |