[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Checking user-id's and paswords



Alex Satrapa said:
: 
: You probably know this already.. but this "if" statement could be written
: much more concisely as:
: 
:  print ($xxx eq 'true') ? "OK" : "Nogo", "\n";

You probably know this already, but to post code that doesn't work is a
Bad Thing. Running with -w gives:
   print (...) interpreted as function at -e line 1.
   Useless use of a constant in void context at -e line 1.
   Useless use of a constant in void context at -e line 1.
   Useless use of a constant in void context at -e line 1.
And prints "1" if $xxx eq 'true' and prints nothing if not.

Print sees parens and acts like a function, so the ternary conditional
stuff is not processed within print's argument list. This is well
explained in the beginning of perlfunc. In particular, it notes that:
   print(1+2) + 3;     # Prints 3.


Consider using either of these:
   print $xxx eq 'true' ? "OK" : "Nogo", "\n";      # [1]
   print (($xxx eq 'true') ? "OK" : "Nogo", "\n");  # [2]

[1] Don't really need parens, since perlop notes that the order of
    precendence is eq above ?: above , (pretty convenient).
[2] But if eq were too low, you'd have to put the whole argument list
    to print in parens. 

In the perlop example:
:       printf "I have %d dog%s.\n", $n,
:               ($n == 1) ? '' : "s";
Note lack of openning paren immediately following "print".

: Windows 95: n. 32 bit extensions and a graphical shell for a 16 bit patch
: to an 8 bit operating system originally coded for a 4 bit microprocessor,
: written by a 2 bit company.

This, however, is entirely correct.

-- 
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch