in reply to Re: Wanting Validation for Smacking my Sysadmin (500 error problem)
in thread Wanting Validation for Smacking my Sysadmin (500 error problem)

The bit of code

local STDOUT; select((select(STDOUT), $|++)[0]);

threw back a 'can't modify constant' error. BUT,

print "HTTP/1.1 200 OK"

made the script work fine (well, I never tried it verbatim--I added a semicolon to the end c",) )

So I should probably be happy (which I am), but now you've got to tell me what the little snippet means.

Thanks! -Petras

Replies are listed 'Best First'.
Re: Re: Wanting Validation for Smacking my Sysadmin (500 error problem)
by robartes (Priest) on Jan 23, 2003 at 16:30 UTC
    The snippet unbuffers the I/O to STDOUT, by setting $| to true. Running it, I just noticed that you can't do local STDOUT;, as STDOUT is not a variable, but a constant referring to file descriptor 1. The snippet works without that part.

    What it does, working inside out, is:

    $|++;
    set currently selected file descriptor to unbuffered I/O
    select(STDOUT);
    make STDOUT currently selected file descriptor. This returns the previously selected FD.
    select ( ( select(STDOUT),$++)[0]);
    Select the first value in the list (select(STDOUT),$|++), which is the return value of select(STDOUT), which is the previously selected file descriptor.

    The snippet basically sets STDOUT to unbuffered I/O whilst preserving the previously selected filehandle as selected. Have a look in perlfaq for a better explanation.

    CU
    Robartes-