Hi Uri; On Mon, Mar 22, 2010 at 15:50, Uri Guttman <[email protected]> wrote:
> >>>>> "KW" == Kenneth Wolcott <[email protected]> writes: > > KW> Hi Harry; > KW> On Mon, Mar 22, 2010 at 12:25, Harry Putnam <[email protected]> > wrote: > > >> Harry Putnam <[email protected]> writes:But even then I still got > what I > >> needed... or until someone tells me > >> its better to in this case not to use IO::Handle but stick with Jim > >> Gs' suggestion: > >> > >> select LOGNAME; > >> $|++; > >> select STDOUT; > > KW> Which is what the Perl Cookbook suggests as well. > > the cookbook isn't always the best answer. check out how they suggest to > read a file backwards. its poor design led me to code up > File::Readbackwards. > > in this case they are wrong again. what if (albeit a rare condition) > STDOUT wasn't the currently selected handle before that code ran? the > correct way is to get the old handle from the select call (which returns > it) and reselect it: > > my $old_handle = select LOGNAME ; > $|++ ; > select $old_handle ; > > as for its using symbolic handle names, that is old too. in any case > using the OO form is even better. > > and another point, never mention the name FileHandle. it is a very > obsolete module and it only wraps IO::Handle anyhow these days. never a > need for it, nor to ever mention it. > > uri > Hmmm...copy&paste from the Safari online Perl Cookbook, 2nd ed: $old_fh = select(OUTPUT_HANDLE); $| = 1; select($old_fh); Looks pretty close to your code, but not the same. Ken Wolcott
