What is the difference between these two code snippets?
open (MYFILE, '>>data.txt');
open (MYFILE, '>data.txt');
From stackoverflow
-
open (MYFILE, '>>data.txt')
— Opendata.txt
, keep the original data, append data from the end.open (MYFILE, '>data.txt')
— Opendata.txt
, delete everything inside, and write data from the start.
From
perldoc -f open
:If MODE is
'<'
or nothing, the file is opened for input. If MODE is'>'
, the file is truncated and opened for output, being created if necessary. If MODE is'>>'
, the file is opened for appending, again being created if necessary.It stems from the shell usage that,
cmd < file.txt
to copy file into stdin,cmd > file.txt
to write stdout into a file, andcmd >> file.txt
to append stdout to the end of the file.
KennyTM : @mirod: `open(MYFILE, '>data.txt')` is equivalent to `open(MYFILE, '>', 'data.txt')`. Please read the link.KennyTM : @mirod: Ok, I see what you mean. Updated to make it clearer.
0 comments:
Post a Comment