uksza has asked for the wisdom of the Perl Monks concerning the following question:
or something like this...my out1 = system("logger bla bla"); my out2 = system("cp 1.txt 2.txt"); my out3 = `/usr/bin/copy 1.txt 2.txt`;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: System vs modules
by davorg (Chancellor) on Aug 05, 2005 at 13:31 UTC | |
I'd always use a Perl implementation in preference to an external program for two reasons: There are probably other good reasons, but those two are enough for me.
-- <http://dave.org.uk> "The first rule of Perl club is you do not talk about
Perl club." | [reply] |
|
Re: System vs modules
by jeteve (Pilgrim) on Aug 05, 2005 at 13:31 UTC | |
In my system, there's no /usr/bin/copy so if your release your code, no chance it will work on my system. File::Copy is part of the standard perl itself, so there's no reason not to use it ! I don't know syslog. I usually use Log::Log4perl . But the idea is the same! Use modules !! Hope it helps.
Nice photos of naked perl sources here !
| [reply] |
by tinita (Parson) on Aug 05, 2005 at 13:47 UTC | |
File::Copy is part of the standard perl itself, so there's no reason not to use it !
except that it doesn't copy file permissions and stuff like that. | [reply] |
|
Re: System vs modules
by Joost (Canon) on Aug 05, 2005 at 13:34 UTC | |
File::Copy is portable to every OS perl runs on as far as I know, while cp and copy are not available on every OS. I tend to use File::Copy for all my copying needs. On the other hand, I've worked on some solaris installs where Sys::Syslog was not available. YMMV. In general, using modules is faster than forking off an external program, especially if you call a lot of them, but some external programs are more efficient than the equivalent perl module, especially when dealing with huge files.
| [reply] |
|
Re: System vs modules
by anonymized user 468275 (Curate) on Aug 05, 2005 at 13:53 UTC | |
- it might be that the program in question is restricted to interfacing with a non-portable system anyway - some modules aren't portable - the portability of other solutions within the same system may have been addressed in a way incompatible with the perl module. - (etc.) Moreover, assuming a module is indeed the best solution for the situation, modular design considerations suggest that you shouldn't plaster it's use all over your application, but rather make your own application as modular as possible by putting your own wrapper module round the usage of the perl module or set of related modules. For example, instead of using Data::Dumper in every module and main program under the sun, you might consider having one module called MyDebug.pm that uses Data::Dumper and checks a global variable for whether or not your data debugging requirements are enabled. The biggest benefit of this idea is when you find a requirement has to change, you want to be prepared by such techniques to minimise the modifications, instead of potentially searching and editing throughout an entire source tree. One world, one people | [reply] |
|
Re: System vs modules
by mikeraz (Friar) on Aug 05, 2005 at 15:42 UTC | |
Why use Perl at all? That, to me, is the essence of your question. If your Perl code is a sequence of system calls you could save yourself some grief with a shell script or batch file.
Certainly when you're starting in Perl a construct like Now your program will tag each line of your log message with the string PERLSEZ, include the process ID, and send it all to the mail logging system. Later on your program can (an action taken thousands of times a day by my system, but that's a different thread) Sys::Syslog provides full control over logging. Note that you don't get to specify the facility, which log type, with /usr/bin/logger. Along with the full control your openlog call will set up some global options so you don't have to specify them on each call. Handy. The other Perl replacements for varied system "command [args]" have their unique advantages. Best of all you get to do both. Use system ...; until you have a frustration with what it won't do for you then investigate what Perl and CPAN have to offer for alternatives. Play with a few, choose the one that floats your boat and implement it.
Be Appropriate && Follow Your Curiosity
| [reply] [d/l] [select] |
|
Re: System vs modules
by Anonymous Monk on Aug 05, 2005 at 14:06 UTC | |
OTOH, I've been using Sys::Syslog for many, many years. I tend to use modules if they are good, they are not doing something different than what they are supposed to replace, and if they don't require more typing. I still use my $text = `cat file`; - it does what I need it to do, and it's short. | [reply] [d/l] [select] |