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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:31:15+00:00 2026-05-26T11:31:15+00:00

I keep on getting initialization errors in this code on the use strict and

  • 0

I keep on getting initialization errors in this code on the use strict and can’t figure out why. I set the scope right for all the variables – and the codes runs. Just don’t understand the ugly errors.

2/15/2002   Joe   155
2/15/2002   Mike  108
2/15/2002   Pete  209
2/22/2002   Joe   158
2/22/2002   Mike  99
2/22/2002   Pete  163
3/1/2002    Joe   172
3/1/2002    Mike  125
#!/usr/bin/perl -w
our %dates;
foreach my $line (<>) {
    chomp $line;
    my ($this_date, $this_name, $this_score) = split /\s+/, $line;
    my ($record_name, $record_score) = split /\|/, $dates{$this_date};
    if ($this_name && $this_score) {
            if ($this_score > $record_score) {
                    $dates{$this_date} = join "|", ($this_name, $this_score);
            }
    }
}

foreach my $date (keys %dates) {
    my ($name, $score ) = split /\|/, $dates{$date};
    print " The high_scored for $date was $name with $score\n";
shortcasper@shortcasper-laptop:~/perl$ ./hash_bowl bowl_linux
Use of uninitialized value in split at ./hash_bowl line 8,  line 7.
Use of uninitialized value $record_score in numeric gt (>) at ./hash_bowl line 10,    line 7.
Use of uninitialized value in split at ./hash_bowl line 8,  line 7.
Use of uninitialized value $record_score in numeric gt (>) at ./hash_bowl line 10,    line 7.
The high_scored for 3/1/2002 was Joe with 172
The high_scored for 2/15/2002 was Pete with 209
shortcasper@shortcasper-laptop:~/perl$
  • 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-26T11:31:15+00:00Added an answer on May 26, 2026 at 11:31 am

    You should use warnings instead of using -w.

    The reason it complains is that the first time you encounter a particular day, $dates{$this_date} is undef (because it’s never been set). Splitting that gives you a warning and makes $record_name and $record_score undef (causing your second warning when you compare $this_score to $record_score). The code works because numerically, undef is considered 0, but it generates warnings.

    A simple fix is to use $dates{$this_date} || '|0' instead. This provides a default value for new dates, setting $record_name to the empty string and $record_score to 0:

    use strict;
    use warnings;
    
    our %dates;
    foreach my $line (<DATA>) {
        chomp $line;
        my ($this_date, $this_name, $this_score) = split /\s+/, $line;
        my ($record_name, $record_score) = split /\|/, $dates{$this_date} || '|0';
        if ($this_name && $this_score) {
                if ($this_score > $record_score) {
                        $dates{$this_date} = join "|", ($this_name, $this_score);
                }
        }
    }
    
    foreach my $date (keys %dates) {
        my ($name, $score ) = split /\|/, $dates{$date};
        print " The high_scored for $date was $name with $score\n";
    }
    
    __DATA__
    2/15/2002   Joe   155
    2/15/2002   Mike  108
    2/15/2002   Pete  209
    2/22/2002   Joe   158
    2/22/2002   Mike  99
    2/22/2002   Pete  163
    3/1/2002    Joe   172
    3/1/2002    Mike  125
    

    But you should read the Perl Data Structures Cookbook and consider using a complex data structure instead of having to join and split your data just to store it in a hash.

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

Sidebar

Related Questions

I keep getting this weird output from my code everytime I use the 'start
I keep getting Clang errors on the following type of code and I can't
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep getting this NPE in my application and I can't seem to get
I keep getting this statement Invalid use of group function for this query mysql_query(UPDATE
I keep getting uncaught handler error in this code and I don't know why.
I keep getting this error Object reference not set to an instance of an
i keep getting Compilation errors when i try to do this . .is there
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting compiler errors when I try to access flashVars in an AS3

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.