Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on a hash tab

Status
Not open for further replies.

nightJohnBoy

Programmer
Joined
Apr 18, 2007
Messages
2
Location
GB
Hi guys,
I need a light help on create a perl tool for work.
Basically I have a file that I want to read into a hash table that will costing of the following.

Identifier/Code, Period, Unit Charge, Min charge, Fixed Charge

an example record could be:
4417862,Evening, 0.01,0.00,0.00
4417862,Daytime, 0.03,0.054,0.00


I will then read in a new file that will check against the identifier and period and allow me to select the unit charge, min charge and fixed charge. Which will aid in the calculation.

Its been ages since I have done anything in perl and I am a little rusty.

Thanks in advance.
John
 
You'd probably want to use a hash of hashes for this.. the structure would look like:
Code:
%identifiers = (
    
    4417862 => {
        period          => "Evening",
        unit_charge     => 0.01,
        min_charge      => 0.00,
        fixed_charge    => 0.00
    },
    
    4417862 => {
        period          => "Daytime",
        unit_charge     => 0.03,
        min_charge      => 0.054,
        fixed_charge    => 0.00
    },
);

to print the period for identifier 4417862, you'd use:

print $identifiers{4417862}{period};

check perldoc perldsc for more on this and how to populate the hash dynamically (Generation of a HASH OF HASHES)
 
ah-ha its all coming back to me now. fred, barny and wilma.

Thanks. This is going to be a nice development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top