H
hernan gonzalez
This is very simple, and is driving me nuts.
I have a perl script which just reads using <> with no record
separator (from the docs: 'You may set $/ to "undef" to read through
the end of file') and prints.
It works ok .. but when used with the inplace editing (perl -pi) it
rotates the lines. (??)
See the test case below:
[tested with perl 5.8.7 on cygwin/winxp, and perl 5.8.0 on slackware
9.0]
/home/hjg $ cat trivial.pl
$/ = undef;
$t = <>;
print $t;
/home/hjg $ cat x.txt
line 1
line 2
line 3
/home/hjg $ ls -l x.txt
-rw-r--r-- 1 hjg hjg 21 May 7 17:27 x.txt
(21 bytes: 3 lines x 7 chars)
/home/hjg $ perl trivial.pl x.txt > x1.txt
/home/hjg $ cat x1.txt
line 1
line 2
line 3
(everything ok here... but now...)
/home/hjg $ perl -pi trivial.pl x.txt
/home/hjg $ cat x.txt
line 2
line 3
line 1
(??? lets try again)
/home/hjg $ perl -pi trivial.pl x.txt
/home/hjg $ cat x.txt
line 3
line 1
line 2
Could someone please tell me what the hell is happening here ??
Thanks!
Hernan
I have a perl script which just reads using <> with no record
separator (from the docs: 'You may set $/ to "undef" to read through
the end of file') and prints.
It works ok .. but when used with the inplace editing (perl -pi) it
rotates the lines. (??)
See the test case below:
[tested with perl 5.8.7 on cygwin/winxp, and perl 5.8.0 on slackware
9.0]
/home/hjg $ cat trivial.pl
$/ = undef;
$t = <>;
print $t;
/home/hjg $ cat x.txt
line 1
line 2
line 3
/home/hjg $ ls -l x.txt
-rw-r--r-- 1 hjg hjg 21 May 7 17:27 x.txt
(21 bytes: 3 lines x 7 chars)
/home/hjg $ perl trivial.pl x.txt > x1.txt
/home/hjg $ cat x1.txt
line 1
line 2
line 3
(everything ok here... but now...)
/home/hjg $ perl -pi trivial.pl x.txt
/home/hjg $ cat x.txt
line 2
line 3
line 1
(??? lets try again)
/home/hjg $ perl -pi trivial.pl x.txt
/home/hjg $ cat x.txt
line 3
line 1
line 2
Could someone please tell me what the hell is happening here ??
Thanks!
Hernan