Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Stumped on an array ref error...

by wog (Curate)
on Oct 07, 2001 at 06:49 UTC ( [id://117261]=note: print w/replies, xml ) Need Help??


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 || * ||----||

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-26 02:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found