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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:40:46+00:00 2026-05-25T14:40:46+00:00

Consider the following snippet: use strict; use warnings; my %a = ( a =>

  • 0

Consider the following snippet:

use strict;
use warnings;

my %a = ( a => 1,
          b => 2,
          c => 'cucu',
          d => undef,
          r => 1,
          br => 2,
          cr => 'cucu',
          dr => '321312321',

        );

my $c = %a;

print $c;

The result of this is 5/8 and I don’t understand what this represents. I read somewhere that a number from this fraction looking result might represent the number of buckets from the hash, but clearly this is not the case.

Does anyone knows how a perl hash is evaluated in scalar context?

Edit

I added a few other hashes to print:

use strict;
use warnings;

use 5.010;


my %a = ( a => 1,
          b => 2,
          c => 'cucu',
          d => undef,
          r => 1,
          br => 2,
          cr => 'cucu',
          dr => '321312321',

        );

my $c = %a;

say $c; # 5/8


%a = ( a => 1,
       b => 21,
       c => 'cucu',
       br => 2,
       cr => 'cucu',
       dr => '321312321',

      );

 $c = %a;

say $c; # 4/8

%a = ( a => 1,
       b => 2,
       c => 'cucu',
       d => undef,
       r => 1,
       br => 2,
       cr => 'cucu',
       dr => '321312321',
       drr => '32131232122',
      );

 $c = %a;

say $c; #6/8

So, you call a ‘tuple’ like a => 1 a bucket in the hash? in that case, why is the last hash still having 8 as a denominator when it has 9 ‘tuples’ ?

Thank you all for your responses until now 🙂

  • 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-25T14:40:47+00:00Added an answer on May 25, 2026 at 2:40 pm

    [The OP is asking about the format of the string returned by a hash in scalar context before Perl 5.26. Since Perl 5.26, a hash in scalar context no longer returns a string in this format, returning the number of elements in the hash instead. If you need the value discussed here, you can use Hash::Util‘s bucket_ratio().]

    A hash is an array of linked lists. A hashing function converts the key into a number which is used as the index of the array element ("bucket") into which to store the value. The linked list handles the case where more than one key hashes to the same index ("collision").

    The denominator of the fraction is the total number of buckets.

    The numerator of the fraction is the number of buckets which has one or more elements.

    For hashes with the same number of elements, the higher the number, the better. The one that returns 6/8 has fewer collisions than the one that returns 4/8.

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

Sidebar

Related Questions

Consider the following code snippet: String input = Print this; System.out.println(input.matches(\\bthis\\b)); Output false What
Consider the following snippet: $(document).bind('mousemove', function(e) { $('#someDiv').css({left: e.pageX+'px', top: e.pageY+'px'}); }); This should
Consider the following snippet: puts 'hello'.gsub(/.+/, '\0 \\0 \\\0 \\\\0') This prints ( as
Consider the following snippet: struct ObjectInterface { virtual ~ObjectInterface() {} virtual void Print(std::ostream& target)
Consider the following code snippet: #!/bin/bash #This program tests the if statement in bash.
Consider the following snippet: using System; using System.Collections.Generic; using System.Linq; using System.Net; namespace ForumLogins
Consider the following snippet of code: // get number of sheep in DataTable by
Consider the following snippet: get '/hello/:name' do |n| Hello #{n}! end How can I
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code snippet: $beat = date('B'); // 1 beat = 86.4 seconds,

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.