in reply to Stumped on an array ref error...

The problem is that for @{$cacheHOA{$sum}} to be an array, then $cacheHOA{$sum} must be an arrayref. You are trying to use $cacheHOA{$sum} as a string and an arrayref, but perl only has it as the last thing it was set has, which appears to be string (the file name) in this case.

Replies are listed 'Best First'.
Re: Re: Stumped on an array ref error...
by Madams (Pilgrim) on Oct 07, 2001 at 07:17 UTC
    Hey wog

    I don't see where i'm trying to use $cacheHOA{$sum} as a string. Per perlfunc:

    exists EXPR Given an expression that specifies a hash element or array element, re +turns true if the specified element in the hash or array has ever bee +n initialized, even if the corresponding value is undefined. The elem +ent is not autovivified if it doesn't exist.


    That doesn't seem to imply any certain context scalar or other..

    This is just stumping me...
    _________________
    madams@scc.net
    (__) (\/) /-------\/ / | 666 || * ||----||
      The exsits operation is not the problem. What the error message says is that $cacheHOA{$sum} contains a string, apparently a file name, and when you do $#{$cacheHOA{$sum}} you are trying to use that string as an arrayref. You have not given enough code to show us where you are setting$cacheHOA{$sum} to a string, removing the arrayref that, presumably, was in there.
        Thanks wog,

        Your response about the exists operation lead me to really look at where the array ref is installed. I changed the following line (where ever it occured):

        $cacheHOA{$sum}=($name);


        to 2 separate lines:

        $cacheHOA{$sum}=(); push @{$cacheHOA{$sum}}, $name;


        and now it works, obviously i thought i was (in the one line version) assigning an annon array with one member, which also obviously did not work (why not?).

        In the two line version i explicitly assigned an empty list and then pushed the member in.

        Thanks for letting me bounce this off of y'all! Sometimes all you need is to have someone look at what your doing and say "Dude, you fscked that right here!"(points and smacks your head...)
        _________________
        madams@scc.net
        (__) (\/) /-------\/ / | 666 || * ||----||