|Welcome to the Monastery|
Re: How to open an editor from your Perl script?by pvaldes (Chaplain)
|on Jul 24, 2012 at 11:28 UTC||Need Help??|
"This allows the user to make changes to the file and save those changes".
I don't feel very comfortable about this idea.
If you open the file, dump to a var and change the var inside the perl script you can benefit of several perl features. If you call and external editor, probably not
"Users are dumb/can't be trusted". An user could enter an error making your script totally crash or doing unexpected things i.e change the var $file to undef or even passing another little script or malware inside $file to be passed to the rest of the script. Or substitute all contents of your var $file by the word "null". Sounds like a bad idea to me.
If a naive user can open your file, what stops her/him to use the editor to copy, reopen, move, rename, change the codification of this file instead to do what you expected?
If you want to change a file you probably will want to use regexes. Some editors are more convenient to others for doing this, but, I can't really see the point of doing this having perl.
There is not point into opening a very big file and then search for a point of this file if you want retrieve and change only a small paragraph/line of interest. With perl you can obtain only the lines needed, split the huge file in several chunks, pick up only the interesting columns... If something crash you could risk to loose all the file.
What if you don't have vim? well, you fail
You want to change a file but your editor opens the file in read-only mode for some reason. fail.
What if you change to a computer with another operative system? fail again. Not multiplataform (without some extra-pain)
What if vim fails to open for a unknow reason like a damaged file? you don't have the same level of info that die provides, (or is not so easily available)
How do you deal with two files with same name when you are in a chdir different that you think?. What if you open or truncate the wrong file? Open looks safer.
etc, etc, etc...