develooper Front page | perl.perl5.porters | Postings from August 2008

print interpreted as function (was: Re: SURPRISE(?): return() VSother builtin()s)

Thread Previous | Thread Next
From:
Abigail
Date:
August 3, 2008 15:30
Subject:
print interpreted as function (was: Re: SURPRISE(?): return() VSother builtin()s)
Message ID:
20080803223001.GK29536@almanda
On Sun, Aug 03, 2008 at 03:41:01PM -0600, Tom Christiansen wrote:
> 
>     4.  Are you surprised that the [CcD]_print functions elicit
>         no "print interpreted as function" warning?


No.


The "print interpreted as function" is not only the most worthless
warning in Perl; it not only generates an awful lot of false positives,
it also misses out cases where it should have warn.


For instance:


  print(1)                       # No warning.
  print (1)                      # Warning.
  print	(1)                      # No (!) warning.   (It's a tab, not a space)
  print  (1)                     # No warning.


  print (1)                      # Warning.
  printf (1)                     # Warning.
  sprintf (1)                    # No warning.
  log (1)                        # No warning.
  sort (1)                       # Warning.


  print ($_)                     # Warning.
  print ($))                     # No warning.


  print (1) || die;              # No warning.
  print (1) && die;              # Warns in 5.8.8; not in 5.10.
  print (1) and die;             # No warning.
  print (1) or die;              # No warning.
  print (1) xor die;             # Warning.


  print (1) for f ();            # Warns in 5.8.8; not in 5.10.
  print (1) if f ();             # No warning.
  print (1) unless f ();         # No warning.
  print (1) while f ();          # No warning.


  do {print (1); next} if f ();  # No warning.
  if (f ()) {print (1)}          # No warning.
  print ($_), next if f ();      # Warning.


And now for the truly bizar:

  print ("1")                    # Warning.
  print ("1");                   # No warning.
  print (")")                    # Warning.
  print (")");                   # Warning.
  print (");")                   # No warning.
  print ("(")                    # Warning.
  print ("(");                   # Warning.
  print (");"), next if f ()     # No warning.
  print ("(;"), next if f ()     # Warning.




When I compile a perl intended for actual use, I first rip out the first
if statement of S_checkcomma in toke.c. 

I once submitted a patch for that against the core, but that was rejected.
People actually seem to be fond of this beast.


Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About