Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 38087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:39:10+00:00 2026-05-10T14:39:10+00:00

In Perl, an object is just a reference to any of the basic Perl

  • 0

In Perl, an object is just a reference to any of the basic Perl data types that has been blessed into a particular class. When you use the ref() function on an unblessed reference, you are told what data type the reference points to. However, when you call ref() on a blessed reference, you are returned the name of the package that reference has been blessed into.

I want to know the actual underlying type of the blessed reference. How can I determine this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:39:10+00:00Added an answer on May 10, 2026 at 2:39 pm

    Scalar::Util::reftype() is the cleanest solution. The Scalar::Util module was added to the Perl core in version 5.7 but is available for older versions (5.004 or later) from CPAN.

    You can also probe with UNIVERSAL::isa():

    $x->isa('HASH')             # if $x is known to be an object UNIVERSAL::isa($x, 'HASH')  # if $x might not be an object or reference 

    Obviously, you’d also have to check for ARRAY and SCALAR types. The UNIVERSAL module (which serves as the base class for all objects) has been part of the core since Perl 5.003.

    Another way — easy but a little dirty — is to stringify the reference. Assuming that the class hasn’t overloaded stringification you’ll get back something resembling Class=HASH(0x1234ABCD), which you can parse to extract the underlying data type:

    my $type = ($object =~ /=(.+)\(0x[0-9a-f]+\)$/i); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing Perl script that uses the FTP object to send a
I recently read Object Oriented Exception Handling in Perl Perl.com article. Is there any
How can I go about populating a simple Java object with data from any
I have been using PerlXS to write a perl wrapper around a C++ Object.
Perl has OOP features, but they are somewhat rarely used. How do you create
PERL? Perl? perl? What's good style? I know the answer—I just wanted to make
Perl uses reference counting for GC, and it's quite easy to make a circular
I wrote a perl script using Tie::Handle::CSV to process a bunch of data in
I wrote a persistent network service in Perl that runs on Linux. Unfortunately, as
I've just started to learn about tie . I have a class named Link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.