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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:14:53+00:00 2026-06-18T04:14:53+00:00

Can anyone tell me where I am wrong? I can’t figure it out…. Basically

  • 0

Can anyone tell me where I am wrong? I can’t figure it out….
Basically what my code is trying to do is to read the files and create a hash for each file, these hashes are organized into on hash. The user would input two parameters, one is the key of the outer hash, and the other is for the one inside.
The ones I input are city and PIT; the same as the parameter I wrote before the line that breaks down….

I tried thousands of times, I keep getting this error: Can’t use an undefined value as a HASH reference I have commented that line out in the code.
The two files are cities.txt; school.txt.
Their content are just as below:
PIT\tPittsburgh
NY\tNewYork

#!/bin/perl -w
use strict;
use Data::Dumper;
our %hash_all = ();
sub readHash{
    my @vars = @_;
    my $filename = $vars[0];
    my %iptable = ();
    if(open(IN,$filename.".txt")) {
            while(<IN>) {   
            my @tmp = split(/\t/);
            $iptable{$tmp[0]} = $tmp[1];
        }
    }
    return %iptable;
}

sub loadAll{
        my %school = readHash("school");
    my %city = readHash("cities");
    $hash_all{school} = \%school;
    $hash_all{city} = \%city;
    print Dumper(\%hash_all);
}

 sub queryValue{
    my @pars = @_;
    my $key1 = $pars[0];
    my $key2 = $pars[1];

    print "key1".$key1;
    print "key2".$key2;
    print Dumper(\%hash_all);   
    my %temp = %{$hash_all{"city"}};#THIS LINE WORKS
    print $temp{"PIT"}; #THIS LINE WORKS
    my %temp2 = %{$hash_all{$key1}};#THIS LINE HAS AN ERROR
    print $temp2{$key2};
}

loadAll();
my $par1 = <>;
my $par2 = <>;
queryValue($par1,$par2);
  • 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-06-18T04:14:54+00:00Added an answer on June 18, 2026 at 4:14 am

    Your problem is probably that when you read in $par1 and $par2, they include newlines at the end. So you end up looking for a hash key like "city\n", which is not the same as "city".

    Make sure you use chomp on your input parameters, like chomp($par1) . That should take care of it.

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

Sidebar

Related Questions

can anyone tell me what is wrong with this code: CC = C:\Program Files\Microsoft
can anyone tell me what is wrong in this code? redis.hdel(hash: + id +
Can anyone tell me what is wrong with this code? I'm trying to determine
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me what's wrong with this code? It's giving me an error
Can anyone tell me what is wrong with this code? public abstract class BoardTestBean{
Can anyone tell what is wrong with the code. $timezone = Asia/Karachi; $date =
Can anyone tell me what's wrong with this code? It is supposed to display
Can anyone tell me whats wrong with this code? <?php $feedID = '28241415'; $oddsArray

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.