Why this code does not do what I mean?
- by Mike
$w = 'self-powering';
%h = (self => 'self',
power => 'pau?',
);
if ($w =~ /(\w+)-(\w+)ing$/ && $1~~%h && $2~~%h && $h{$2}=~/?$/) {
$p = $h{$1}.$h{$2}.'ri?';
print "$w:"," [","$p","] ";
}
I expect the output to be
self-powering: selfpau?ri?
But what I get is:
self-powering: [ri?]
My guess is something's wrong with the code
$h{$2}=~/?$/
It seems that when I use
$h{$2}!~/?$/
Perl will do what I mean but why I can't get "self-powering: selfpau?ri?"?
What am I doing wrong? Any ideas?
Thanks as always for any comments/suggestions/pointers :)