I would like to answer the underlying reason why editing the lines of text in-situ is not possible. Consider what the file actually is in terms of byte storage 0000000 # ! / u s r / l o c a l / b i
+n
043 041 057 165 163 162 057 154 157 143 141 154 057 142 151 15
+6
0000020 / p e r l - w \n u s e s t
+r
057 160 145 162 154 040 055 167 012 165 163 145 040 163 164 16
+2
0000040 i c t ; \n p r i n t " H e l
+l
151 143 164 073 012 160 162 151 156 164 040 042 110 145 154 15
+4
0000060 o W o r l d \ n " ; \n
157 040 127 157 162 154 144 134 156 042 073 012
0000074
To change bytes in the middle may be possible, but to increase the length of lines would involve inserting bytes (hence shuffling the remainder forwards).
Also, this is just how text files are implemented on one operating system (Unix). Others may use different line terminators, or implement in a completely diferent way, such as VMS, which stores the text file as a series of variable length records. Anything which relies of the Unix representation will potentially be non-portable. |