Why am I getting unexpected output trying to write a hash structure to a file?

Posted by Harm De Weirdt on Stack Overflow See other posts from Stack Overflow or by Harm De Weirdt
Published on 2010-03-23T19:52:59Z Indexed on 2010/03/23 22:13 UTC
Read the original article Hit count: 211

Filed under:

I have a hash in which I store the products a customer buys (%orders). It uses the product code as key and has a reference to an array with the other info as value.

At the end of the program, I have to rewrite the inventory to the updated version (i.e. subtract the quantity of the bought items)

This is how I do rewrite the inventory:

sub rewriteInventory{
    foreach $key(%inventory){
        print FILE "$key\|$inventory{$key}[0]\|$inventory{$key}[1]\|$inventory{$key}[2]\n"

where $inventory{$key}[x] is 0Title, 1price, 2quantity.

The problem here is that when I look at inv.txt afterwards, I see things like this:

CD-911|Lady Gaga - The Fame|15.99|21
BOOK-1453|The Da Vinci Code - Dan Brown|14.75|12

Where do these ARRAY(0x145030c)||| entries come from? Or more important, how do I get rid of them?

© Stack Overflow or respective owner

Related posts about perl

Related posts about hashtable