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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:45:39+00:00 2026-05-15T18:45:39+00:00

I have a source list from which I am picking up random items and

  • 0

I have a source list from which I am picking up random items and populating the destination list. The item that are in the list have a particular format. For example:

item1{'name'}
item1{'date'}

etc and many more fields.

while inserting into the destination list I check for unique names on items and insert it into that list. For this I have to traverse the entire destination list to check if an item with a given name exists and if not insert it.

I thought it would be nice if I make the destination list as hash instead of a list again so that I can look up for the item faster and efficiently. I am new to Perl and am not getting how to do this. Anybody, Please help me on how to insert an item, find for a particular item name, and delete an item in hash?

How can I make both the name and date as key and the entire item as value?

  • 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-15T18:45:39+00:00Added an answer on May 15, 2026 at 6:45 pm

    my %hash;

    1. Insert an item $V with a key $K?

      $hash{$K} = $V

    2. Find for a particular name / key $K?

        if (exists $hash{$K}) { 
            print "it is in there with value '$hash{$K}'\n";
        } else { 
            print "it is NOT in there\n" 
        }
    
    1. Delete a particular name / key?

      delete $hash{$K}

    2. Make name and date as key and entire item as value?

    Easy Way: Just string everything together

    set: $hash{ "$name:$date" } = "$name:$date:$field1:$field2"
    get: my ($name2,$date2,$field1,$field2) = split ':', $hash{ "$name:$date" }
    del: delete $hash{ "$name:$date" }
    

    Harder Way: Store as a hash in the hash (google “perl object”)

    set:

    my %temp;
    $temp{"name"} = $name;
    $temp{"date"} = $date;
    $temp{"field1"} = $field1;
    $temp{"field2"} = $field2
    
    $hash{"$name:$date"} = \$temp;
    

    get:

    my $find = exists $hash{"$name:$date"} ? $hash{"$name:$date"} : undef;
    if (defined find) { # i.e. it was found
        printf "field 1 is %s\n", $find->{"field1"}
    } else {
        print "Not found\n";
    }
    

    delete:

    delete $hash{"$name:$date"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Lion, source list group items now have a Hide/Show button that appears when
Suppose I have two lists that holds the list of source file names and
I have a list view which is bound to a DataTable source. The sorting
I have a list of object that is the data source. Something like that:
I have a small application that uses a SharePoint list as the data source.
I have a scenario in which i receive files from a source and i
OK So I have a combo box which selects an administrator from a list
I have a source of data that changes from time to time. When it
I have a dictionary/list balance_sign_dict from which I need to retrieve 2 values based
I have a data model in which I have an Item that can belong

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.