in reply to Re: Re: Re: Flag variables
in thread Flag variables
Using the hash reference to return the sub name...
It's worth pointing out that it doesn't actually return the name of the sub, but rather a coderef for the sub.
Whilst you could name the subs with the same name as the value used to look them up, and then avoid the need to use the hash at all, that would be an example of using symbolic references with all the inherent dangers that implies.
By storing and looking up a coderef to the action subroutines, you avoid the possibility of attempting to invoke a non-existant subroutine if $var has an unexpected value and more importantly, avoid the possibility of invoking one of the potentially dangerous built-ins if the contents of $var has been deliberately tampered with.
|
|---|