Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The error I recieve is "Use of uninitialized value in string eq at analyze-frequencies.pl line 21, <FILE> line 283 (#1) Use of uninitialized value in string eq at analyze-frequencies.pl line 18, <FILE> line 284 (#1) Use of uninitialized value in string eq at analyze-frequencies.pl line 21, <FILE> line 284 (#1) Followed by the desired output : Animal Id Station 1 Station 2 a23 6 0 a37 12 4 a45 0 10 ... I am really unsure as to why I am getting this error. I thought I initialized my hashes and the $s1{animal_id} = 0; part too. I am at my wits end regarding this, I've spend quite a few hours and this is all I have. Thanks for taking the time to read my plea for help ; ;#!/usr/bin/perl -w use strict; use warnings; use diagnostics; my %s1 = (); #initialize hashes my %s2 = (); open FILE, "stations.log" or die "cannot open file stations.log:\, it +does not exist. $!\n"; #open file for reading while (<FILE>){ my $station_visits = $_; #initialize variable and set to the file +which was opened chomp ($station_visits); #CHOMP! my ($animal_id, $date , $station) = split/:/, $station_visits; #sp +lit on colons $s1{animal_id} = 0; $s2{animal_id} = 0; if ($s1{$animal_id} eq undef){ #if there is no value for $s1{anima +l_id}, set it to 0 $s1{$animal_id} = 0; } if ($s2{$animal_id} eq undef){ #if there is no value for $s2{animal +_id}, set it to 0 $s2{$animal_id} = 0; } #number of times animal visits station 1 if ($station eq 's1'){ #If the animal vists station 1, create, to + 0, and add 1. # if (not exists($s1{$animal_id})){ # $s1{$animal_id} = 0; #} $s1{$animal_id} = $s1{$animal_id} + 1; } else{# ($station eq 's2'){ #if (not exists($s2{$animal_id})){ #If the animal vists stati +on 2, create, to 0, and add 1. # $s2{$animal_id} = 0; # } $s2{$animal_id} = $s2{$animal_id} + 1; } } print "Animal Id\tStation 1\t Station 2\n"; foreach my $animal_id (sort keys (%s1)){ #for each hash, print values + into a table print "$animal_id \t\t $s1{$animal_id} \t\t $s2{$animal_id}\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialized errors when using 2 hashes.
by ssandv (Hermit) on Oct 22, 2010 at 22:39 UTC | |
|
Re: Uninitialized errors when using 2 hashes.
by AnomalousMonk (Archbishop) on Oct 23, 2010 at 04:10 UTC | |
|
Re: Uninitialized errors when using 2 hashes.
by shevek (Beadle) on Oct 23, 2010 at 10:44 UTC | |
|
Re: Uninitialized errors when using 2 hashes.
by Tails (Novice) on Oct 22, 2010 at 23:16 UTC | |
|
Re: Uninitialized errors when using 2 hashes.
by choroba (Cardinal) on Oct 22, 2010 at 22:26 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |