in reply to Help with strict

If you use the hash %masters, you don't need the exists. Either $master{$nick} has the value 1, which is true, or else it is undefined, which is false. This also has the benefit of no longer having a routine referencee a global variable.

If you aren't quite ready to delete the is_master subroutine, quite yet, modify the beginning of subroutine to:

my $who = $_[0]; my $grant = 0; print "Nick is '$who'\n"; print "Called from ", join( ", ", caller()), ,"\n\n";

That should simplify debugging.

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Help with strict
by hardburn (Abbot) on Oct 28, 2003 at 19:51 UTC

    The point of putting an exists in is that it works independantly of the actual value in the hash. Perhaps in the future, the program would be expanded to add levels of 'mastery' over the bot, which is implemented by putting different values in the %masters datastructure. In that case, exists $masters{$user} would still tell you if $user is a master, even if it's a user at level 0.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

      Ah, but if you encapsulate the check in is_master, you only have to update that function once if you ever decide to track user levels.