Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: System vs modules

by mikeraz (Friar)
on Aug 05, 2005 at 15:42 UTC ( [id://481285]=note: print w/replies, xml ) Need Help??


in reply to System vs modules

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
     $retval = system "logger -t PERLSEZ TIMTOWTDI Rulz!"
is a safe and familiar way to get the word out. So (to continue using this example) you can wonder why Tom and Larry bothered to code up Sys::Syslog and what they did to make it worth using. A quick check of the CPAN page shows that you can start by

use Sys::Syslog; openlog "PERLSEZ", "pid", "LOG_MAIL"; # say it once and let Sys::Syslo +g remember for the duration, save me some typing later # add code as needed
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
syslog "info", "spammer trying dictionary attack blocking $ipaddr";
(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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-18 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found