hesco has asked for the wisdom of the Perl Monks concerning the following question:

Stumped by hash declaration related errors.

UPDATE: Yes, of course, an anonymous hash! Thank you rhesa, liverpole and jwkrahn. That ran it through to completion for the first time in several disjointed stolen moments with this code over a week or two. Building this test suite is the 'hobby' project waiting in a distant window for me to have breaks from other projects. This question got composed last night after too many hours of staring at php code for a client, before such a stolen moment. Before being finally submitted this evening during another such moment.

This code:

$test_subscriptions->{"test_case-$j"} = ( 'fname' => $lname, 'lname' => $fname, 'zip' => '02486', 'email' => $email, 'lists' => ['news','updates','vols-annc'], );
is throwing the following errors:

Useless use of a constant in void context at line 130. Useless use of private variable in void context at line 130. Useless use of a constant in void context at line 130. Useless use of private variable in void context at line 130. Useless use of a constant in void context at line 130. Useless use of a constant in void context at line 130. Useless use of a constant in void context at line 130. Useless use of private variable in void context at line 130. Useless use of a constant in void context at line 130. Can't call method "isa" without a package or object reference at line +66.
Any clues appreciated.

-- Hugh

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: What useless about that?
by liverpole (Monsignor) on Nov 10, 2006 at 00:35 UTC
    Hi hesco,

    The problem is that you're trying to assign to a hash reference, but you're using parentheses "( ... )" instead of braces "{ ... }".

    Try this instead:

    $test_subscriptions->{"test_case-$j"} = { 'fname' => $lname, 'lname' => $fname, 'zip' => '02486', 'email' => $email, 'lists' => ['news','updates','vols-annc'], }

    Update:  Oh, and I'm betting that in your program, line 124 is the one containing

    $test_subscriptions->{"test_case-$j"} = {
    because that's where I had to position the hash assignment to get exactly the same wording as in the error message you got.  But I don't know what's going on with your line 66:
    Can't call method "isa" without a package or object reference at line +66.

    For that one, you'll have to give us more clues ;-)


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: What useless about that?
by jwkrahn (Abbot) on Nov 10, 2006 at 00:39 UTC
    Your code evaluates to:
    $test_subscriptions->{"test_case-$j"} = ['news','updates','vols-annc'] +;

    The rest of the code evaluates to constants in void context. Perhaps you meant to assign an anonymous array instead:
    $test_subscriptions->{"test_case-$j"} = [ 'fname' => $lname, 'lname' => $fname, 'zip' => '02486', 'email' => $email, 'lists' => ['news','updates','vols-annc'], ];

    Or an anonymous hash:
    $test_subscriptions->{"test_case-$j"} = { 'fname' => $lname, 'lname' => $fname, 'zip' => '02486', 'email' => $email, 'lists' => ['news','updates','vols-annc'], };
Re: What useless about that?
by rhesa (Vicar) on Nov 10, 2006 at 00:34 UTC
    I don't think these errors are caused by this assignment. It sounds like you missed a semicolon or a quote or something a little before this line. We'd need to see more code to be sure though.

    The assignment does look flawed on its own though: you're assigning a list to a scalar, and that won't do what you expect. I'm guessing you meant to assign a hashref instead of a list. Replace the outer braces with curlies, and this bit should work.

    Update: rats, thrown off by that "isa" error! The "useless" errors _are_ caused by the assignment to the scalar.

      The "useless" errors _are_ caused by the assignment to the scalar.

      Indirectly. Directly, they are caused by the use of rvalues on the lefthand side of the comma operator. (However, the scalar context supplied by the assignment is driving the choice of comma operator to the one that supplies void context on the left, so that _is_ related.)


      Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.