J
Justin C
I can't seem to access the values in a hash of hashes, but if I iterate
over it I'm able to print all the values. The error I get if I try to
access one value is :
Use of uninitialized value in print at ./test line 20, <PRICES> line 62.
I've done the best I can in reducing this to the smallest possible code
that works, it's still quite long, sorry about that.
======= START CODE =======
#!/usr/bin/perl
use warnings ;
use strict ;
my %priceHash ;
my $zone = 5 ;
my $weight = 5 ;
lookupCost() ;
#for $weight ( keys %priceHash ) {
# print "$weight : " ;
# for $zone ( keys %{$priceHash{$weight}} ) {
# print "\t", $zone, "=", $priceHash{$weight}{$zone}, "\n" ;
# }
# print "\n" ;
#}
print "Price = ", $priceHash{$weight}{$zone}, "\n" ;
sub lookupCost {
open PRICES, "<", "/var/www/inhouse/pforce/pforcePrices.csv"
or die "Cannot opne prices csv file: $!" ;
my @lines = <PRICES> ;
my $header = shift @lines ;
chomp $header ;
$header =~ s/\cM//g ; # MS CR/LF
$header =~ s/zone//ig ;
$header =~ s/\s+//g ;
my @zones = split /,/ , $header ;
shift @zones ; #first one is empty
foreach ( @lines ) {
chomp ;
s/\cM//g ;
my @prices = split /,/ ;
my $kg = shift @prices ;
foreach ( @zones ) {
$priceHash{$kg}{$_} = shift @prices ;
}
}
}
======= CODE END =======
If I comment the "print" line and uncomment the itteration over the
hashes it prints, for each weight, the different zones and the prices
for those zones. It appears to me that all of the information is in the
hash but I'm not accessing the individual values correctly.
The .csv, if you want to try this out, can be found at:
http://81.6.247.208/pforcePrices.csv I didn't paste it here because of
the size (it's not too big, but it's not appropriate for a usenet post).
I thank you for any help you can give with this.
Justin.
over it I'm able to print all the values. The error I get if I try to
access one value is :
Use of uninitialized value in print at ./test line 20, <PRICES> line 62.
I've done the best I can in reducing this to the smallest possible code
that works, it's still quite long, sorry about that.
======= START CODE =======
#!/usr/bin/perl
use warnings ;
use strict ;
my %priceHash ;
my $zone = 5 ;
my $weight = 5 ;
lookupCost() ;
#for $weight ( keys %priceHash ) {
# print "$weight : " ;
# for $zone ( keys %{$priceHash{$weight}} ) {
# print "\t", $zone, "=", $priceHash{$weight}{$zone}, "\n" ;
# }
# print "\n" ;
#}
print "Price = ", $priceHash{$weight}{$zone}, "\n" ;
sub lookupCost {
open PRICES, "<", "/var/www/inhouse/pforce/pforcePrices.csv"
or die "Cannot opne prices csv file: $!" ;
my @lines = <PRICES> ;
my $header = shift @lines ;
chomp $header ;
$header =~ s/\cM//g ; # MS CR/LF
$header =~ s/zone//ig ;
$header =~ s/\s+//g ;
my @zones = split /,/ , $header ;
shift @zones ; #first one is empty
foreach ( @lines ) {
chomp ;
s/\cM//g ;
my @prices = split /,/ ;
my $kg = shift @prices ;
foreach ( @zones ) {
$priceHash{$kg}{$_} = shift @prices ;
}
}
}
======= CODE END =======
If I comment the "print" line and uncomment the itteration over the
hashes it prints, for each weight, the different zones and the prices
for those zones. It appears to me that all of the information is in the
hash but I'm not accessing the individual values correctly.
The .csv, if you want to try this out, can be found at:
http://81.6.247.208/pforcePrices.csv I didn't paste it here because of
the size (it's not too big, but it's not appropriate for a usenet post).
I thank you for any help you can give with this.
Justin.