View Single Post
  #4  
Old 02-13-2013, 09:01 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

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";
}
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;
Reply With Quote