in reply to Slicing the output of a command
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Slicing the output of a command
by marioroy (Prior) on Jul 10, 2015 at 03:13 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2015 at 03:35 UTC | |
by marioroy (Prior) on Jul 10, 2015 at 04:00 UTC | |
by afoken (Chancellor) on Jul 10, 2015 at 10:21 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2015 at 11:17 UTC |