in reply to arrays, context, and print - oh my.

print (1,2,3,4)[1];
means printing "1234", then getting the second element of the list returned by print - except that perl can't parse it. Which is not what you mean - so perl warns you about that (it's already a syntax error, yet you get a warning as well). However, its heuristics when to warn are were coded by a squirrel being high on glue: So, we get the absurd:
print(1) # No warning. print (1) # Warning. print (1) # No warning. printf (1) # Warning. sprintf (1) # No warning. print (1) # No warning. print (1) || die; # No warning. print (1) or die; # No warning. print (1) xor die; # Warning. print (1) and die; # No warning. print (1) && die; # Warning. print (1) == 1 # No warning. print (1) != 1 # No warning. print (1) <=> 1 # Warning. print (1); next # No warning. print (1), next # Warning. print (1) | next # No warning. print (1) & next # Warning. print ("(") # Warning. print (")") # Warning. print ("1"); # No warning (trailing semi-colon). print (")"); # Warning (even with semi-colon). print ("1"); die; # No warning. print ("("); die; # Warning.
With such an illogical mess, you won't see me advocating to enable warnings.

I heard this warning will play a major role in Dan Browns new novel.

Replies are listed 'Best First'.
Re^2: arrays, context, and print - oh my.
by eric256 (Parson) on Aug 09, 2005 at 18:51 UTC

    I can certainly see why one set of warnings specificaly added to a function to address a specific set of common bugs/possible bugs, would lead you to stop advocating warnings.

    The warning is intended to warn you that perl and you might have thought differently on how that statment was phrased, it is not intended to babysit you. If you don't like the current warnings then you could probably help out by supplying the code to make print warn on all those cases.


    ___________
    Eric Hodges
      If you don't like the current warnings then you could probably help out by supplying the code to make print warn on all those cases.
      Believe me, I've tried to make the warnings more sane. I've send in patches. More than once. I've also tried to make remove the warning in its entirely. But if P5P wants to keep the warning as it, how am I supposed to do that?

      BTW, I think perl should print the warning in none of those cases, as all cases I gave there's no error. Although it wouldn't be hard to create some cases where there is an error, but no warning is given.

      The warning is intended to warn you that perl and you might have thought differently on how that statment was phrased, it is not intended to babysit you.
      But you see, perl and I thought exactly the same on how the statement was "phrased", we both thought that "print (...)" was a function call. It's that perl thought I thought that perl thought differently. And that's where I think it goes too far. Such warnings are wrong too often, and warnings that are wrong too often are worse than not having warnings at all.