Name

blessed

Synopsis

blessed expr
                  

Evaluates whether expr is a blessed reference. If successful, blessed returns the name of the package. Otherwise, blessed returns undef.

use Scalar::Util qw(blessed);
use CGI;
 
my $cgi = CGI->new();
my $not_cgi = "IamNotCGI";

my $is_blessed = blessed($cgi);
if(defined($is_blessed) { print "$cgi\n;" } # Prints CGI
 
my $is_blessed2 = blessed($not_cgi);
if(defined($is_blessed2) { print "$not_cgi\n"; } # undef

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.