On Sunday, Nov 16, 2003, at 07:53 US/Pacific, Hacksaw wrote: [..]
If you were never going to do anything else in the while loop, it could be this:
while (<ER>) { print EL $_; }
I think select is one of the statements that you don't need for most small projects. I have never used it in my 6 or so years of perl coding. --
I on the other hand have had the unpleasantry of FORGETTING that I was whacking new code in that was doing a 'select'.
So one solution is to make sure that IF you do a select that you put things back where you found them, eg:
my $oldfh = select($newfh); # the neat new stuff here ... select($oldfh);
as you will notice in the 'perldoc -f select' the nice line notes:
select FILEHANDLE select Returns the currently selected filehandle. Sets the current default filehandle for output, if FILEHANDLE is supplied. This has two effects: first, a "write" or a "print" without a filehandle will default to this FILEHANDLE.
So one begins to need 'select' only when one wants to have a 'naked' print statement rather than the fully formed "print FILEHANDLE LIST" ( cf perldoc -f print ). In the code fragment
print EL $_ while (<ER>);
there is no ambiguity about which filehandles are being used for what.
So IF one adopts the strategy of
print STDOUT $your_message_here ;
then one always knows that one's INTENT was to go to STDOUT and will not cause one's self problems when one has found a reason to use select() for the sort of select(2) system calls that may well come along. This approach protects your code from, well, yourself when you become forgetful.... 8-)
And yes, DO remember the caveat at the end of the select perldoc that notes:
WARNING: One should not attempt to mix buffered I/O (like "read" or <FH>) with "select", except as permitted by POSIX, and even then only on POSIX systems. You have to use "sysread" instead.
but that way leads into very emotionally traumatizing moments of Bashing Large Heavy Objects upside one's head about RTFM! RTFM! RTFM!!!! and promising one's self that they will never write bad code again....
ciao drieux
---
No coding problem is so complex that one can not consult the inner Golum.... My Precious..... and find self reassurance....
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]