cat -E test1.txt
output:
car$
$
$
I want just change "car" with "bike" and remove new/empty lines.
This is working as expected:
#!/usr/bin/perl -w
open(FILE1,"<","./test1.txt"); @araj=<FILE1>; close(FILE1);
open(FILE2,">","./test1.txt");
map {
s@car@bike@; s@^\n@@;
} @araj;
print(FILE2 @araj);
close(FILE2);
and
cat -E test1.txt
output is 100% correct for me:
bike$
But in above case i am using 2x opening/close file.
So i am using 2x file handles.
I want to use only 1x file handle
(it`s for learning purposes, just trying to understand how +> +>> >> are working...).
For example:
#!/usr/bin/perl -w
open(FILE2,"+<","./test1.txt"); #what file handle should be here? +> , +>> >> .... ?
@araj=<FILE2>;
map {
s@car@bike@; s@^\n@@;
} @araj;
print(FILE2 @araj);
close(FILE2);
output is incorrect:
car$
$
$
bike$
Why this is appending, but no overwriting? When i used others file handles, results are also incorrect, for example empty file... Which file handle is used for read-and-overwrite ?