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 6890829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:54+00:00 2026-05-27T06:19:54+00:00

How do Perl hashes work? Are they like arrays in PHP or some completely

  • 0

How do Perl hashes work?
Are they like arrays in PHP or some completely different beast?

From what I understand all it is is an associative array right? This is what I thought until I began
to talk to a Perl programmer who told me I was completely wrong, but couldn’t explain it in a way
that didn’t make my eyes cross.

Anyway, the way that I thought it worked was like this

PHP’s:

$argv['dog_name'] = 'missy';
$argv[0] = 'tree';

same as Perl’s:

my %argv{'dog_name'} = 'missy';
my $argv[0] = 'tree';

Right? But you cannot print(%argv{‘dog_name’}), you have to (revert?) to print($argv{‘dog_name’}) which is confusing?

Is it trying to print as a variable now, like you would in PHP, echo $argv[‘dog_name’]; ? Does this mean (again) that a hash is
just a PHP associative array with a % to declare but a $ to access?

I don’t know, I’m hoping some PHP/Perl Guru can explain how hashes work, and how similar they are
to PHP’s arrays.

  • 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-27T06:19:55+00:00Added an answer on May 27, 2026 at 6:19 am

    To write

    $argv['dog_name'] = 'missy';
    $argv[0] = 'tree';
    

    in Perl, you would write it as follows:

    $argv{dog_name} = 'missy';
    $argv{0}        = 'tree';
    

    if you had strict on, which you should, then you will need to predeclare the variable:

    my %argv;
    $argv{dog_name} = 'missy';
    $argv{0}        = 'tree';
    

    If the above is a bit repetitive for you, you could write it:

    my %argv = (
        dog_name => 'missy',
        0        => 'tree',
    );
    

    You can find more detail on the perldata manpage.

    In short, the reasons why the sigils change from % to $ is that %hash refers to a plural hash (a list of key value pairs), and $hash{foo} refers to a single element of a hash. This is the same with arrays, where @ refers to the full array, and $ refers to a single element. (for both arrays and hashes a leading @ sigil with a subscript means a slice of the data, where multiple keys are passed and a list of values are returned)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to pass some data structures from java to perl. In perl,
I would like to properly understand hashes in Perl. I've had to use Perl
Since arrays and hashes can only contain scalars in Perl, why do you have
In perl , i have an array of hashes like 0 HASH(0x98335e0) 'title' =>
I am a Perl person and I have made Hashes like this for a
Okay, coming from a perl background I am used to Arrays holding refs to
The following perl sub is used to store arrays of hashes. Each hash to
I have a perl hash of hashes like the following: $VAR1 = { 'ID_1'
I am currently learning Perl. I have Perl hash that contains references to hashes
Perl has OOP features, but they are somewhat rarely used. How do you create

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.