It took me a while to figure out what was going on.
Here's my program:
#!/usr/bin/perl
$ARGV[0]="test";
$^I="";
undef $/;
while(<>) { print STDOUT "hello\n" }
$/ seems to work correctly, reading to the end of the file if
set to undef. However, by setting $^I to the null string,
Perl seems to think it is running as if at the command line.
the "while(<>)" reads from the file named "test", but the
print statement writes to that same file. I find that
without STDOUT, file test is erased and filled with a
single "hello". Using the STDOUT filehandle, the file is
erased and set to 0 bytes. Do you see the same activity?
What I don't get is by keeping the same program as above but
inserting $^I=undef; just before the print statement
inplace editing does not seem to get disabled, i.e. the file is
overwritten anyway.
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.