Hameed U. Khan wrote:
> print (('January', 'Fubruary', 'March', 'April', 'May ', 'June',
> 'July', 'August', 'September',
>  'Ooctber', 'November', 'December')[-1]);
> following is the warning and output i am getting.
> 
> [EMAIL PROTECTED] ./backwards.pl
> print (...) interpreted as function at ./backwards.pl line 14.

You can remove the warning by elminating the space between "print" and the
opening parenthesis following.

A more detailed explaination of warning and error messages is in:

   perldoc perldiag

The explanation for this warning is:

   %s (...) interpreted as function
        (W syntax) You've run afoul of the rule that says that any list
        operator followed by parentheses turns into a function, with all
        the list operators arguments found inside the parentheses.  See
        "Terms and List Operators (Leftward)" in perlop.

What this is telling you is that the parentheses are being used to enclose
function call operators, and not for grouping a list term. In fact, the
function call is what you are doing, so everything is OK. Perl is warning
you because normally when the programmer intends a function call, the space
between the function name and parenthesis is omitted.

The example from perldoc perlop is:

   print ($foo & 255) + 1, "\n";

What the programmer appears to want here is to print two things:

   ($foo & 255) + 1
   "\n"

Actually perl interprets this as:

   (print($foo & 255)) + 1, "\n";

because the rule is that if the first non-whitespace thing following a list
operator (print) is an opening parenthesis, it is treated as a function
call.

This example can be corrected by using parens to group all the terms (like
in your code):

   print(($foo & 255) + 1, "\n");

Or, you'll sometimes see it written like this:

   print +($foo & 255) + 1, "\n";

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to