smart match operator with range operator wasn't working for me. i don't know why. this works, however.
Code:
use 5.012;
use warnings;
package NPC;
sub new {
my ( $class, %param ) = ( shift, @_ );
$param{_hp} = ( int rand 9 ) + 1;
return bless \%param, $class;
}
sub GetHP {
shift->{_hp};
}
package main;
my $npc1 = NPC->new();
my $npc2 = NPC->new();
my $hpcheck1 = $npc1->GetHP();
my $hpcheck2 = $npc2->GetHP();
my $lower = $hpcheck2 - $hpcheck2 * .10;
my $upper = $hpcheck2 + $hpcheck2 * .10;
if ( $hpcheck1 >= $lower && $hpcheck1 <= $upper ) {
say "$hpcheck1 is within $lower and $upper";
}
else {
say "$hpcheck1 is NOT within $lower and $upper";
}