Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Re: Sometimes it's in Void Context

by JayBonci (Curate)
on Jun 01, 2002 at 02:01 UTC ( [id://170867]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Sometimes it's in Void Context
in thread Sometimes it's in Void Context

Okay, lemme know if I'm wrong here, but:
$lines[0] = [ 3,2,1 ];
The brackets are forming an array context. You're assigning an array to the array member
print $lines[0][ 3,2,1 ];
I am assuming what is going here is that the array dereference is looking for a numerical value to figure out where to look in the array. You get the same error here:
print scalar(4,5); jaybonci@starlite:~/perl/pm$ ./array.pl Useless use of a constant in void context at ./array.pl line 6. 5jaybonci@starlite:~/perl/pm$
Looking at the comma operator in the perlop page, this makes sense. The values are evaluated one by one.

It wouldn't make sense for perl to be looking for an array in a dereference operator, because you need a numerical value. Why would it map those values or try to return a sub array based on those values. The execution order says to resolve the commas first.

Like I said, I could be way off.

    --jb

Replies are listed 'Best First'.
Re^4: Sometimes it's in Void Context
by Aristotle (Chancellor) on Jun 01, 2002 at 18:29 UTC

    You misunderstood the question, just like dws did. I didn't get it until just a few moments ago either. Ovid's question is not "why does this not work as initially expected", nor "why do I get this warning", it is "why do I get the warning sometimes".

    In your example, if you change print scalar(4,5); to print scalar(0,1);, you will get no warnings. His question is why and when that happens.

    As chromatic quotes the perl source, that's the case because the warning is kludged not to trigger for the two values 0 and 1.

    ____________
    Makeshifts last the longest.
      My goof. In my original writeup (before i edited it down a bit). I had mentioned the special case for 1 and 0. Now if only I had posted that.... Alas.

          --jb

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found