Jeff Westman wrote:
This will work (thanks)....
Tell me, is there a way to cross-reference the file handle to the variable I am using? Suppose I have something like open(IN, "< $myFile) Can I do some kind of system call to see what variable name is associated with 'IN'?
Alternatively, I guess, I could do something like open(IN, "< $myFile) && ($myFileNum = fileno(IN)) or die "open failed"
Thoughts??
Watch out for equality rather than assignment in the above if statement...
assuming $myFileNum contains an integer then the above test should work like so:
if ($myFileNum == fileno(IN)) { # IN has the same file descriptor as $myFileNum } else { # doesn't }
Not sure when, but in the life of Perl 5 it became possible to store a file handle in a lexical variable, if it helps with what you are trying to accomplish like so:
my $IN; open($IN,"< $myFile") or die "Couldn't open file for reading: $!"; while (<$IN>) { # etc... } close($IN) or die "Couldn't close open file: $!";
Always test whether open (and usually close) succeeded. In general I would think you would not want to test open and a file descriptor in teh same sequence, if the open succeeds but it is a different file descriptor (which I am not sure you can predict except for the special cases of 0, 1, 2) then you will be left with an open file but a failed statement, which may produce unexpected results depending on the complexity of your app.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]