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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:21:44+00:00 2026-05-14T01:21:44+00:00

For an assignment in college, we have to make a script in Perl that

  • 0

For an assignment in college, we have to make a script in Perl that allows us to manage an inventory for an e-store. (The example given was Amazon). Users can make orders in a fully text-based environment and the inventory must be updated when an order is completed.

Every item in the inventory has 3 to 4 attributes: a product code, a title, a price and for some an amount (MP3’s for example do not have this attribute)

Since this is my first encounter with Perl, I don’t really know how to start. My main problem is how I should “implement” the inventory in the program. One of the functions of the program is searching trough the titles. Another is to make an order, where the user should give a product code.

My first idea was a hash with the productcode as key. But if I wanted to search in the titles that could be a problem because of this:
the hashkey would be something like DVD-123, the information belonging to that key could be “The Green Mask 12” (without quotes) where the 12 indicates how many of this DVD are currently in stock. So I’d have to find a way to ignore the 12 in the end.

Another solution was to use the title as the key, but that would prove cumbersome too I think.

Is there a way to make a hash table with 2 keys, and when I give only one it returns an array with the other values? (Including the other key and the other information)
That way I could use another key depending on what info I need from my inventory.

We have to read the default inventory from a text file looking like this:

MP3-72|Lady Gaga - Kiss and Run (Fear of Commitment Monster)|0.99  
CD-400|Kings of Leon - Only By The Night|14.50|2  
MP3-401|Kings of Leon - Closer|0.85  
DVD-144|Live Free or Die Hard|14.99|2  
SOFT-864|Windows Vista|49.95  
  • 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-14T01:21:44+00:00Added an answer on May 14, 2026 at 1:21 am

    Since your course presumably does not cover SQL or databases, you may find it useful to represent your inventory as a hash of hashes.

    Inventory items will be hash references:

    my $die_hard_4 = { code => 'DVD-144', title => 'Live Free or Die Hard', price => 14.99, stock => 2 };
    

    Your inventory itself will be a hash:

    my %inventory;
    $inventory{'DVD-144'} = $die_hard_4;
    

    You can create another hash to index your inventory by title:

    my %inventory_by_title;
    $inventory_by_title{'Live Free or Die Hard'} = $die_hard_4;
    

    All that remains is to parse the inventory file format into a hashref like the one above. As a quick example:

    my %inventory;
    my %inventory_by_title;
    
    while ( <> ) {   # for each line of input
        chomp;  # remove trailing newline
        my ($code, $title, $price, $amount) = split /\|/;  # split by '|' character
        my $item = {
            code => $code,
            title => $title,
            price => $price,
            stock => $amount,
        };
        $inventory{$code} = $item;
        $inventory_by_title{$title} = $item;
    }
    

    Hope this helps you get started.

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

Sidebar

Related Questions

I have the following code that I am working on for my college assignment.
I'm doing a college assignment in XNA to make a virtual piano. I have
I am doing a college assignment in Java that deals with currency. For that
I have an assignment to be done in college, a piece asks for the
I am trying to complete a college assignment in Perl, and we've been told
I have an assignment in college in which we are required to read in
I have been working on a college C assignment, and have been trying to
I am a student in college and have an assignment which requires finding large
I have been trying to complete the following assignment for my college. So far,
I'm very new to XML and XSLT. I have a homework assignment that asks

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.