HP ProLiant G6 Servers: Perform like a superstar, Save like an accountant.
Hello, Guest | Login | Register

Holy Camels, Batman!

Like Barman, Perl has its own” utility belts”, namely Scalar::Util and List::Util. Here’s a look at what each gizmo can do.

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:

 use Scalar::Util qw(blessed); blessed "foo"; # undef blessed bless [], "Foo"; # "Foo" blessed bless {}, "Bar"; # "Bar" 

At first glance, this seems similar to the ref builtin function. However, consider this:

 ref []; # "ARRAY" blessed []; # undef 

For an unblessed reference, ref returns the primitive data type (such as…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!


Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow linuxdlsazine