Why this code does not do what I mean?
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2010-03-08T13:02:48Z
Indexed on
2010/03/08
13:06 UTC
Read the original article
Hit count: 193
$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 :)
© Stack Overflow or respective owner