Every once in a while, there is some activity which is relatively simple to perform using a shell command, but would be somewhat inconvenient using Perl commands. The down side is that it's generally sloppy.

If you're going to get the contents of a file, and you're dealing with a very short throw-away script, it might make sense to `cat` it.

But you're launching a shell (many milliseconds), opening the file (some milliseconds), loading all it's contents into memory, outputting the contents from the sub-process to the Perl script. If you open a file in Perl, it takes the same amount of time as when you do it in a sub-shell, even though you have to open() the file, <read> the contents, just no sub-shell.

Just about anything you want to do, is available internally in Perl, either built-in, provided by a core module, or availaable as an add-on module. Go to Cpan.org or metacpan.org or search for what you need. For example, gzip-ing or gunzip-ing a file is as simple as use-ing the module, and specifying something in the open() command.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: Slicing the output of a command by TomDLux
in thread Slicing the output of a command by fbicknel

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.