I'm the author of Pythonizer and I'm trying to translate the code of CGI.pm from the standard perl library to Python. I came across this code in read_from_client:
read(\*STDIN, $$buff, $len, $offset)
Is \*STDIN the same thing as just STDIN? I'm not understanding why they are using it this way. Thanks for your help!
The module also references \*main::STDIN - is this the same as STDIN too (I would translate plain STDIN to sys.stdin in python)? Code:
foreach my $fh (
\*main::STDOUT,
\*main::STDIN,
\*main::STDERR,
) { ... }
The following can usually be used a file handle:
*STDIN{IO})*STDIN)\*STDIN)"STDIN")The builtin operators that expect a file handle allow you to omit the
*when providing a glob. For example,read( FH, ... )meansread( *FH, ... ).The builtin functions that expect a file handle should accept all of these. So you could any of the following:
read( *STDIN{IO}, ... )read( STDIN, ... )read( *STDIN, ... )read( \*STDIN, ... )read( "STDIN", ... ).They will have the same effect.
Third-party libraries probably accept the globs and reference to globs, and they should also expect IO objects. I expect the least support for providing the name as a string. Your mileage may vary.
You can't go wrong with a reference to a glob (
\*FH) since that's whatopen( my $fh, ... )produces.