N
Nene
Why is this code not working?
#!/usr/bin/perl -w
use strict;
use warnings;
my %years;
while (<DATA>) {
chomp;
my $year = (split /\t/)[3];
$years{$year}++;
}
foreach (sort keys %years) {
print "In $_, $years{$_} CDs were released.\n";
}
__DATA__
Bragg, Billy Workers' Playtime Cooking Vinyl 1987
Bragg, Billy Mermaid Avenue EMI 1998
Black, Mary The Holy Ground Grapevine 1993
Black, Mary Circus Grapevine 1996
Bowie, David Hunky Dory RCA 1971
Bowie, David Earthling EMI 1987
~
###
I keep getting:
rsimionis-macbook-pro:c2 Rod$ ./hash.pl
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 1.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 2.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 3.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 4.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 5.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 6.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 7.
In , 7 CDs were released.
#!/usr/bin/perl -w
use strict;
use warnings;
my %years;
while (<DATA>) {
chomp;
my $year = (split /\t/)[3];
$years{$year}++;
}
foreach (sort keys %years) {
print "In $_, $years{$_} CDs were released.\n";
}
__DATA__
Bragg, Billy Workers' Playtime Cooking Vinyl 1987
Bragg, Billy Mermaid Avenue EMI 1998
Black, Mary The Holy Ground Grapevine 1993
Black, Mary Circus Grapevine 1996
Bowie, David Hunky Dory RCA 1971
Bowie, David Earthling EMI 1987
~
###
I keep getting:
rsimionis-macbook-pro:c2 Rod$ ./hash.pl
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 1.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 2.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 3.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 4.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 5.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 6.
Use of uninitialized value in hash element at ./hash.pl line 9, <DATA>
line 7.
In , 7 CDs were released.