Cheers all,
I recently stumbled over $subject -
for $foo ('a'..'c') { open FH,'|-', 'cat -'; select FH; for $bar (1..rand 10) { write } $- = 0; close FH; } format FH_TOP = =@= $foo . format FH = @ $bar . __END__ =a= 1 2 3 4 5 1 2 3 4 5 1 2
switching the lines with the $- assignment and close yields
for $foo ('a'..'c') { open FH,'|-', 'cat -'; select FH; for $bar (1..rand 10) { write } close FH; $- = 0; } format FH_TOP = =@= $foo . format FH = @ $bar . __END__ =a= 1 2 3 4 =b= 1 2 =c= 1 2
If the filehandle is pristine, $- is 0. But after the first close it is set to $= (page length), thus write skips format TOP.
In the source, in Perl_do_close() in doio.c (thanks mtve for pointing to it):
if (not_implicit) { IoLINES(io) = 0; IoPAGE(io) = 0; IoLINES_LEFT(io) = IoPAGE_LEN(io); }
Why?
It's not documented either. Anybody knows the rationale for that? - I know, that's an old corner of perl. I just want to know.
In reply to close() resets $- to $=, not 0 by shmem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |