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?
|