One of my favorite television lines comes from the mid-’60s, campy Batman television series. Whenever Batman (played by Adam West, who I sat next to during a cross-country flight a few years ago — that was a fun conversation) was stuck in a tight situation, he uttered the painfully halting “must.… get to… my… utility… belt.” Everything Batman needed to escape the episode’s trouble was in that belt, if somewhat magically. If he needed to repel sharks, there it was, the shark repellant. If Batman needed to dissolve glue, yep, there’s the glue dissolver. What a magical time of television!
Perl also has its own “utility belts,” namely Scalar::Util and List::Util. These modules were added into the core around Perl version 5.8, although you can install both from the CPAN into any modern Perl version. This time, let’s take a look at what the Scalar::Util utility belt contains. Next month, we’ll look at List::Util.
The blessed function of Scalar::Util tells us the classname of a blessed reference, or undef otherwise. (By default, neither of these modules export any subroutines, so you must ask for these functions explicitly by import.) For example: