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

  • Home
  • SEARCH
  • 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 6078413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:49:51+00:00 2026-05-23T10:49:51+00:00

$ref = \%hash; $ref = \@hash; How do I do the same thing as

  • 0
$ref = \%hash;
$ref = \@hash;

How do I do the same thing as reference using typeglob in perl?

What’s the exact steps perl takes to interpret $$ref{key}?

  • 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. Editorial Team
    Editorial Team
    2026-05-23T10:49:52+00:00Added an answer on May 23, 2026 at 10:49 am

    If you’re asking how you get a reference to a type glob, it’s just:

    my $ref = \*symbol_name_here;
    

    For a “literal name” of the symbol, (that is where you type in the exact name of the symbol), and not a variable. But, you can do this:

    my $ref = Symbol::qualify_to_ref( $symbol_name );
    

    for a variable symbol. However, the above works with strict and the easier one below doesn’t:

    my $ref = \*{$symbol_name};
    

    One of the nice things about Symbol::qualify*, is that it handles package names as the second variable. So…

    my $sref = Symbol::qualify_to_ref( $symbol_name, $some_other_package );
    

    does the same thing as \*{$some_other_package.'::'.$symbol_name} and it works with strict.

    Once you have the symbol ref, to get the slot, you have to deference the reference, so perl does not think you’re trying to use it as a hash, like so.

    my $href  = *{ $sref }{HASH};
    my $code  = *{ $sref }{CODE};
    my $arref = *{ $sref }{ARRAY};
    my $io    = *{ $sref }{IO};
    

    Another Take

    I put your two ideas together in a different way. If you have a symbol table reference, you can get the HASH slot and that is a reference just like any other reference to a hash. So you can do the following.

    Either

    *hash{HASH}->{key}
    

    Or

    ${ *hash{HASH} }{key}
    

    will work. These are safer, though

    ( *hash{HASH} || {} )->{key};
    ${ *hash{HASH} || {} }{key};
    

    If you want to do this not with a direct entry, but a reference into the table, you would do the following:

    my $ref   = \*hash;
    my $value = *{ $ref }{HASH} && *{ $ref }{HASH}->{key};
    

    NOTE: %hash absolutely needs to be a package variable. Only package variables reside in the symbol table (so only subs and @ISA and Exporter variables tend to be in modern symbol tables). Lexical variables (those declared my) reside in the “pad”.


    UPDATE:

    • I have gotten away from using Symbol so much. Curiously, even though it is core, it seems non-standard in the way Perlers do–and see–things. Instead, I use the direct way in what I call “no-blocks”, as localized as I can make them.

      # All I want is one symbol. 
      # Turn strict-refs off, get it, turn it back on.
      my $symb = do { no strict 'refs'; \*{$symbol_name} };
      

      OR

      {   no strict 'refs';
          *{$package_name.'::'.$symbol_name} = $sub_I_created;
          ... # more reckless symbol table mucking...
      }
      
    • I almost always use the *STDERR{IO} idiom for a glob file handle reference. In modern Perl, these are usually objects.

      my $fh = *STDERR{IO};
      say blessed( $fh ); # IO::File
      $fh->say( 'Some stuff' );
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand full the ref word in the .NET Since using the same variable,
suppose $my_ref = \$hash{'mary'}; #my_ref is a reference point to a hash element. ....
Initially, I was looking for a fast way to access a hash ref element
When printing a reference to an array, hash, etc, what is that hexadecimal number
Let's assume that I have a complex hash reference $hash_ref , and I would
I write a sub in Perl to merge 2 hashes of the same structure;
Lets say I have the following Perl hash: %hash = ( 'A' => {
Ref. to my last post and sellibitze's comment to that post on passing array
public ref class ScriptEditor : public Form { public: typedef map<UInt32, ScriptEditor^> AlMap; static
Is Interlocked.Increment(ref x) faster or slower than x++ for ints and longs on various

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.