Perl's
open seems to behave differently in UNIX and Windows, and the behavior under Windows is *odd*, or I am doing something dumb.
This script:
#!/usr/local/perl-5.6.1/bin/perl
use strict;
$|=1;
eval {
open (FOO,">/tmp/tmp/tmp/tmp") ||die
print FOO "hello";
close FOO;
};
if ($@) {
print "open failed $@";
}
me@unixsystem:/tmp# ./fp.pl
open failed Died at ./fp.pl line 6.
This fails like I thought it should because /tmp/tmp/tmp does not exist, and my message is printed. The directory needs to be made before we can create files there.
Under Windows, similar code:
use strict;
$|=1;
eval {
open (FOO,">c:\gpp\gpp\gpp") ||die;
print FOO "hello";
close FOO;
};
if ($@) {
print "open failed $@";
}
Runs successfully (does not print error message) when the c:\gpp\gpp directory does not exist. It does not create any file either. If I try and open a file on an q:\gpp\gpp (in this case an unmapped drive), it does actually die and trigger my error message.
Does anyone know what the problem is here?
Rohit
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.