troubleshooting Question

Ways of calling another perl script

Avatar of Mazdajai
MazdajaiFlag for United States of America asked on
PerlScripting Languages
12 Comments1 Solution514 ViewsLast Modified:
I understand there are multiple ways to call another script within a perl script - system(), require(), use(), do().

Looking at the man page, my opinion seems like require() is preferred. On a modern perl perspective, would that be true?

In my example, I have many scripts that would like to call a email script with NET::SMTP, sendmail.pl.

sendmail.pl
#!/usr/bin/perl
#
use Net::SMTP;

my $infile = 'body.txt';
open(INFILE,"< $infile");
@file = <INFILE>;
close INFILE;
my $smtp_host = 'smtp.example.com';
my $from = "host1";
my $to = 'receipient@example.com';
if (length($ENV{HOSTNAME} ne "")) {$machine = $ENV{HOSTNAME};}
else {$machine = $ENV{COMPUTERNAME};}
my $subject = "Server(s) with corrupt file system records";
my $smtp = Net::SMTP->new($smtp_host,Timeout=>30,Debug=>1);
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend(<<END_OF_MESSAGE);
To: $to
#Bcc: $to
From: $from
Subject: $subject

@file
END_OF_MESSAGE
$smtp->datasend;
$smtp->quit; 
ASKER CERTIFIED SOLUTION
wilcoxon

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros