Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Given that the bug report suggests only the is_W() function is used from FileHandle::Fmode I don't see why you can't replace the entire dependency with this short sub:

sub is_W { my $fh = shift; return 0 unless defined $fh; return 0 unless defined fileno $fh; local $\ = ''; # just in case no warnings; # temporarily disable warnings #my ($atime,$mtime) = (stat($fh))[8,9]; my $is_w = print $fh ''; #eval{ utime $atime, $mtime, $fh }; # can fail if futimes not avai +lable return $is_w; } my $file = "C:/tmp.txt"; printf "Null fh %d\n", is_W(); open F, ">", $file or die "Can't create $file $!\n"; printf "Writable fh %d\n", is_W(*F); close F; open F, $file or die "Can't create $file $!\n"; printf "Readable fh %d\n", is_W(*F); close F; printf "STDIN %d\n", is_W(*STDIN); printf "STDOUT %d\n", is_W(*STDOUT); printf "STDERR %d\n", is_W(*STDERR); __DATA__ Null fh 0 Writable fh 1 Readable fh 0 STDIN 0 STDOUT 1 STDERR 1

Update added "no warnings;" as per barts suggestion. Added comments containing mtime restoration code (if desired) also per bart.


In reply to Re: Test for writable filehandles on win32 by tachyon-II
in thread Test for writable filehandles on win32 by tsee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found