Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Hash of hashes problem

Posted on 2002-07-11
11
200 Views
Last Modified: 2010-03-05
%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}->{'price'};
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.

0
Comment
Question by:sjaguar13
  • 6
  • 5
11 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7147299
Name "main::Price" used only once: possible typo at 20322330.perl line 9 (#1)
   
    (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)
0
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 7147307
%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);

    $products{$Key}={
         price => $Price,
         description => $SDescription,
    };

}

$blah = $products{isi130}->{'price'};
print "$blah"
0
 

Author Comment

by:sjaguar13
ID: 7147859
Still nothing, just a blank page.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 84

Expert Comment

by:ozo
ID: 7148314
Did you correct all the errors?
What is in filedb.txt?
0
 

Author Comment

by:sjaguar13
ID: 7148375
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?
0
 
LVL 84

Expert Comment

by:ozo
ID: 7148388
Name "main::key" used only once: possible typo at 20322330.perl line 18 (#1)

You probably meant $Key
0
 

Author Comment

by:sjaguar13
ID: 7148404
Yep, you're right again! Changing it to $Key worked. One other thing, how did you get those error messages?
0
 
LVL 84

Expert Comment

by:ozo
ID: 7148415
perl -w 20322330.perl
or
perl -Mdiagnostics -w 20322330.perl
0
 

Author Comment

by:sjaguar13
ID: 7148424
Does that work with Windows, or just linix?
0
 
LVL 84

Expert Comment

by:ozo
ID: 7150919
It works with Windows or Unix
0
 

Author Comment

by:sjaguar13
ID: 7151031
So I type !#C:\perl\bin\perl.exe - 20322330.perl?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Removing file extension within a file. 4 98
Having a problem with ActiveState Perl on 64-bit Windows 7 3 75
Perl modules on linux ec2 3 114
Perl Frameworks 1 98
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question