R
R^3
For some reason, I cannot access a hash with two keys. When I attempt
to print its contents, all I get is whitespace.
If I try to print "$counts{'french',4}"; I get the proper output, but
when I try "$counts{$building,$i}; all I get is whitespace. How can I
fix this????
#!/usr/bin/perl
open (OUT,">data.dat");
my %hash = ();
@masterBuildings = ();
while ($line = <STDIN>)
{
if ($line =~ m/\(Info\): Station (\w+) (Rea|A)ssociated/){
@fields = split " ", $line;
$index = $fields[2];
$building = $fields[5];
$building =~ s/[0-9]+-(wb|ap)$//;
$counts{$building,$index} += 1;
push(@masterBuildings,$building);
}
}
@Buildings = &uniq(@masterBuildings);
foreach $building (@Buildings) {
#$building = "'" . $building . "'";
$i = 2;
while ($i < 7) {
print "$counts{$building, $i}\n";
#does not work, but $counts{'french',4} does.
$i += 1;
}
}
sub uniq {
local(@words) = @_; # local copy of array
local(%MARK); # temporary associative array
grep($MARK{$_}++, @words); # counts each occurance
(ignored)
keys %MARK; # return the unique elements
}
to print its contents, all I get is whitespace.
If I try to print "$counts{'french',4}"; I get the proper output, but
when I try "$counts{$building,$i}; all I get is whitespace. How can I
fix this????
#!/usr/bin/perl
open (OUT,">data.dat");
my %hash = ();
@masterBuildings = ();
while ($line = <STDIN>)
{
if ($line =~ m/\(Info\): Station (\w+) (Rea|A)ssociated/){
@fields = split " ", $line;
$index = $fields[2];
$building = $fields[5];
$building =~ s/[0-9]+-(wb|ap)$//;
$counts{$building,$index} += 1;
push(@masterBuildings,$building);
}
}
@Buildings = &uniq(@masterBuildings);
foreach $building (@Buildings) {
#$building = "'" . $building . "'";
$i = 2;
while ($i < 7) {
print "$counts{$building, $i}\n";
#does not work, but $counts{'french',4} does.
$i += 1;
}
}
sub uniq {
local(@words) = @_; # local copy of array
local(%MARK); # temporary associative array
grep($MARK{$_}++, @words); # counts each occurance
(ignored)
keys %MARK; # return the unique elements
}