in reply to Re^2: substitution in regular experssion
in thread substitution in regular expression
It seems you've edited your node to remove the while loop you originally had. Please don't do that without marking your updates because it confuses things, now monks won't know which version of your question to answer.
... it doesn't seem to work
In what way? Do you get an error, or are you seeing unexpected results? Because it works for me:
use Data::Dumper; print Dumper([build_dictionnary()]); sub build_dictionnary{ my $line="ABCDEF"; my @dic; while(length($line)>2){ $line =~ s/([A-Z]([A-Z]{2}))/$2/; push(@dic, $1); } return @dic; } # Output (whitespace compressed): # $VAR1 = [ 'ABC', 'BCD', 'CDE', 'DEF' ];
I would like to know the way to do it without the while loop.
Why?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: substitution in regular experssion
by aeqr (Novice) on Apr 23, 2014 at 20:21 UTC | |
by AnomalousMonk (Archbishop) on Apr 23, 2014 at 20:34 UTC | |
by aeqr (Novice) on Apr 23, 2014 at 20:41 UTC | |
by Anonymous Monk on Apr 23, 2014 at 20:47 UTC | |
| |
by Anonymous Monk on Apr 23, 2014 at 20:30 UTC |