Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to open an editor from your Perl script?

by pvaldes (Chaplain)
on Jul 24, 2012 at 11:28 UTC ( #983376=note: print w/ replies, xml ) Need Help??


in reply to How to open an editor from your Perl script?

"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...


Comment on Re: How to open an editor from your Perl script?
Re^2: How to open an editor from your Perl script?
by samwyse (Scribe) on Jul 24, 2012 at 14:02 UTC

    I think that this cover most of your points:

    "A man who trusts nobody is apt to be the kind of man nobody trusts." -- Harold MacMillan

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-08-21 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls