use strict;
my $text=q|my name is $name. I have ${config.maximum}. The end|;
my @words=extract($text);
print join(",", @words), "\n";
sub extract {
my $line=shift;
my @tokens;
while(1) {
if ($line =~ /\G\$(\w+)/gc) {
print "\$var: $&, $1\n";
push @tokens, $1;
next;
}
if ($line =~ /\G\$\{([^}]+)\}/gc) {
print "\${namespace.var}: $&, $1\n";
push @tokens, $1;
next;
}
if ($line =~ /\G[^\$]+/gc) {
print "other: $&\n";
next;
}
last;
}
print "\n";
return @tokens;
}
other: my name is
$var: $name, name
other: . I have
${namespace.var}: ${config.maximum}, config.maximum
other: . The end
name,config.maximum