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


In reply to Re: How to open an editor from your Perl script? by pvaldes
in thread How to open an editor from your Perl script? by dr.jekyllandme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.