sjaguar13
asked on
Hash of hashes problem
%product=();
print "Content-type: text/html\n\n";
open(DB, "filedb.txt");
@db = <DB>;
close(DB);
foreach $_ (@db){
($SDescription,$Price,$Key ) = split(/\|/, $_);
chomp($Key);
$products{$key}={
price => $price,
description => $SDescription,
};
}
$blah = $products->{isi130}->{'pri ce'};
print "$blah";
That does nothing. What am I doing wrong? I was a price and description for each key. Everytime I try to print one thing, it comes up blank.
print "Content-type: text/html\n\n";
open(DB, "filedb.txt");
@db = <DB>;
close(DB);
foreach $_ (@db){
($SDescription,$Price,$Key
chomp($Key);
$products{$key}={
price => $price,
description => $SDescription,
};
}
$blah = $products->{isi130}->{'pri
print "$blah";
That does nothing. What am I doing wrong? I was a price and description for each key. Everytime I try to print one thing, it comes up blank.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Still nothing, just a blank page.
Did you correct all the errors?
What is in filedb.txt?
What is in filedb.txt?
ASKER
This is my script:
%products=();
print "Content-type: text/html\n\n";
open(DB, "filedb.txt") or die $!;
@db = <DB>;
close(DB);
foreach ( @db ){
($SDescription,$Price,$Key ) = split(/\|/, $_);
chomp($Key);
print "hi"; #Test to make sure it enters the foreach
$products{$Key}={
price => $Price,
description => $SDescription,
};
print "$products{$key}->{'price' }"; #test to see if it prints the prices..it doesn't
}
$blah = $products{isi130}->{'price '};
print "$blah"; #nothing here
This is filedb.txt:
7 STRING DOUBLE CUTAWAY|299|isi130
NEW YORKER SOLIDTOP HOLLOWBODY ARCHTOP WITH CUTAWAY|Call|nyl-2vb
NEW YORKER SOLIDTOP HOLLOWBODY ARCHTOP WITH CUTAWAY|Call|nyl-2n
CUTAWAY HOLLOWBODY WITH 2 HUMBUCKERS|439|91203178
PRS STYLE WITH STOP TAILPIECE|489|isi342
PRS STYLE WITH SERPENT INLAY|539|c0501193
1972 RE-ISSUE TELECASTER THINLINE|399|dtt72sb
1972 RE-ISSUE TELECASTER THINLINE|399|ddt72blk
1972 RE-ISSUE TELECASTER THINLINE|399|dtt72cab
1972 RE-ISSUE TELECASTER THINLINE||399|ddt72n
STRAT STYLE WITH BRIDGE HUMBUCKER|199|FAT-210
STRAT STYLE WITH BRIDGE HUMBUCKER AND TREMELO|249|FAT-310
SEMI-HOLLOW BODY|759|r98h0538
Did I miss some errors?
%products=();
print "Content-type: text/html\n\n";
open(DB, "filedb.txt") or die $!;
@db = <DB>;
close(DB);
foreach ( @db ){
($SDescription,$Price,$Key
chomp($Key);
print "hi"; #Test to make sure it enters the foreach
$products{$Key}={
price => $Price,
description => $SDescription,
};
print "$products{$key}->{'price'
}
$blah = $products{isi130}->{'price
print "$blah"; #nothing here
This is filedb.txt:
7 STRING DOUBLE CUTAWAY|299|isi130
NEW YORKER SOLIDTOP HOLLOWBODY ARCHTOP WITH CUTAWAY|Call|nyl-2vb
NEW YORKER SOLIDTOP HOLLOWBODY ARCHTOP WITH CUTAWAY|Call|nyl-2n
CUTAWAY HOLLOWBODY WITH 2 HUMBUCKERS|439|91203178
PRS STYLE WITH STOP TAILPIECE|489|isi342
PRS STYLE WITH SERPENT INLAY|539|c0501193
1972 RE-ISSUE TELECASTER THINLINE|399|dtt72sb
1972 RE-ISSUE TELECASTER THINLINE|399|ddt72blk
1972 RE-ISSUE TELECASTER THINLINE|399|dtt72cab
1972 RE-ISSUE TELECASTER THINLINE||399|ddt72n
STRAT STYLE WITH BRIDGE HUMBUCKER|199|FAT-210
STRAT STYLE WITH BRIDGE HUMBUCKER AND TREMELO|249|FAT-310
SEMI-HOLLOW BODY|759|r98h0538
Did I miss some errors?
Name "main::key" used only once: possible typo at 20322330.perl line 18 (#1)
You probably meant $Key
You probably meant $Key
ASKER
Yep, you're right again! Changing it to $Key worked. One other thing, how did you get those error messages?
perl -w 20322330.perl
or
perl -Mdiagnostics -w 20322330.perl
or
perl -Mdiagnostics -w 20322330.perl
ASKER
Does that work with Windows, or just linix?
It works with Windows or Unix
ASKER
So I type !#C:\perl\bin\perl.exe - 20322330.perl?
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention
it again somehow to suppress the message. The our declaration is
provided for this purpose.
Name "main::key" used only once: possible typo at 20322330.perl line 12 (#1)
Name "main::product" used only once: possible typo at 20322330.perl line 1 (#1)
Name "main::price" used only once: possible typo at 20322330.perl line 13 (#1)