I had a few discussions regarding to use or not to use STDIN
in answer written in PHP. Reading from STDIN
is very expensive in PHP consuming 12 bytes:
fgetc(STDIN) // single character
fgets(STDIN) // whole line
Different wordings in requirements
From Implement a Truth Machine
- take input from STDIN or an acceptable alternative
- If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program
My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:
I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages
From Write a Program that Writes a function BUT in a different language!
Write the shortest program that takes one input (n) from STDIN (or equivalent) […]
My answer using STDIN
was also discussed:
Why not just
x=>x+<?=$x;
? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).
My questions
Keeping in mind that STDIN
is available in PHP.
- Do you need to read from
STDIN
in requirements likefrom STDIN or an acceptable alternative
or is any other method acceptable? - Is a command line argument an acceptable alternative to
STDIN
in? - Is using
register_globals=on
acceptable?
If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n]
and fget[c/s](STDIN)
and simply use $a … $n
based on the amount of input values.
This question is narrowed to PHP but the answers may apply for other languages as well.
prompt()
. Specifically, I think that command-line arguments are quite a different way of reading input. While they are allowed by default, if a question specifically asks for STDIN (or alternative), I'd assume they have a good reason for excluding command-line arguments. \$\endgroup\$register_globals
enabled - and won't take the time to set this up just to test a single submission. I think your answers will be less-well received as a result. I typically also assume-n
(no .ini), which makes requiring a deprecated option a somewhat difficult position. \$\endgroup\$