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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:46:43+00:00 2026-05-17T01:46:43+00:00

Initially, I was looking for a fast way to access a hash ref element

  • 0

Initially, I was looking for a fast way to access a hash ref element (with a default value if no value is available).

So I tried the following :

use strict;
use warnings;
use DateTime;
my $hashref = { };
for (0..249) {
  my $lIdx = $_ * 2;
  $hashref->{"MYKEY$lIdx"} = "MYVAL$lIdx";
}

sub WithVariable{
    my $result = $hashref->{"MYKEY$_[0]"};
    return defined $result ? $result : "NONE";
}

sub WithoutVariable{
    return defined $hashref->{"MYKEY$_[0]"} ? $hashref->{"MYKEY$_[0]"} : "NONE";
}
$|++;
my @preciousvalues1 = ();
my @preciousvalues2 = ();
my $dt = DateTime->now;
for (1..25000) { for (0..498) { push @preciousvalues1, WithVariable($_) } }
my $lag = DateTime->now - $dt;
print "With a variable: ", $lag->seconds, "\n";
$dt = DateTime->now;
for (1..25000) { for (0..498) { push @preciousvalues2, WithoutVariable($_) } }
$lag = DateTime->now - $dt;
print "Without a variable: ", $lag->seconds, "\n";

print "Done\n";

But the results seem to be quite random, and perl seems to do a lots of stuff after printing the “Done”, and takes forever to exit.

My questions are :

  1. What would be a neat implementation of a function allowing to access values stored in a hash with a default value if no value is found ?
  2. What the hell is perl doing after it printed “Done” ? Garbage collection ?

Perl version : This is perl, v5.10.1 built for MSWin32-x86-multi-thread

  • 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-17T01:46:43+00:00Added an answer on May 17, 2026 at 1:46 am
    1. Since version 5.10 you can use the // (defined-or) operator to test for defined-ness and assign a default value in one step.
    $result = $hashref->{$key} // "NONE"

    sets $result to $hashref->{$key} if that value is defined, and "NONE" otherwise.

    2. More or less. If it bothers you, slap a

        use POSIX;
        POSIX::_exit(0);
    

    at the end of your script. This will end your script immediately, bypassing Perl’s normal shutdown routine (and any code you have put into END { } blocks). It’s probably not a big deal to use it on this script, but it would normally not be a best practice to use _exit.

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

Sidebar

Related Questions

I initially was looking for a way convert byte to float, and found answers
I'm looking for a way possibly using VBA to apply a cell's fill value
We're looking for a fast, flexible way of generating templated content (in this case
Initially, I was looking at the way pickerData is set and thinking I wonder
I'm looking to achieve the following. I have an initially-empty absolutely positioned div (#description)
I'm looking for a way to list all views in a database. Initially I
Initially I've tried to find possible ways to do HLS segmenting on other non-Mac
I'm looking for a fast and secure cryptography algorithm with C# implementation. I need
Initially I was looking for an answer to show/hide a page jumping issue. Having
i am looking for a method to extract text from web page (initially html)

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.