usenet@carssdf.UUCP (John Watson) (09/20/90)
I seem to be having a problem with even the simplest scripts that use the write stmt. I do something like: open(HNDL); $^ = 'TOP'; $~ = 'FMT'; write(HNDL); etc... and it does not write! (except sometimes), then later on in the same program it will work. Once it starts working, it seems to be ok. Writing to stdout works more ofter it think. Is this a known bug? Is there a work around? John Watson, Middlesex, NJ, USA ...!rutgers!carssdf!usenet
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (09/22/90)
In article <261@carssdf.UUCP> usenet@carssdf.UUCP (John Watson) writes:
: I seem to be having a problem with even the simplest scripts that use
: the write stmt. I do something like:
: open(HNDL); $^ = 'TOP'; $~ = 'FMT'; write(HNDL); etc...
: and it does not write! (except sometimes), then later on in the same
: program it will work. Once it starts working, it seems to be ok. Writing
: to stdout works more ofter it think.
That's because you're setting $^ and $~ for STDOUT, not HNDL. Say
open(HNDL) || die;
local($oldhndl) = select(HNDL);
$^ = 'TOP'; $~ = 'FMT';
select($oldhndl);
...
write(HNDL);
or the way Randal will suggest:
open(HNDL) || die;
select((select(HNDL), $^ = 'TOP', $~ = 'FMT')[0]);
...
write(HNDL);
Larry