1828767 Members
2407 Online
109985 Solutions
New Discussion

Perl Script help

 
Ragni Singh
Super Advisor

Perl Script help

Hello, hope I can get some help with this. Attached is a script written in perl which runs a query out of a database and sends a report out ot a number of people. Some of the folks are not around anymore so I need to remove them from the mailing list. My issue is I don't want to delete them out of teh databas table.

The 4 people receiving them currently are Molly, Bruce, Peter. I would like to remove Bruce and Peter from the distribution list and add Tom to the list.

With in the script, in this particular section..

sub getDistList{
my $C = "select email from rpt_dist where rpt_id = '$_[0]';";
# die "$rptNam";
my $sth=$dbh->prepare($C);
if ( !defined $sth ) {
die "DML Error, Cannot prepare Dist List statement: $DBI::errstr";
}

if($sth->execute){
my $ntuples = $sth->rows;
if ($ntuples > 0) {
for ( my $i=0; $i < $ntuples; $i++) {
@row = $sth->fetchrow; # Get a row
$row[0] = &clip($row[0]);
$distList .= "$row[0]; ";
}
....

within the four loop, how can I add a statement that says to only send mail to Molly, Kim and to not send it to Bruce and Peter.

Tahnks and points will be assigned.
4 REPLIES 4
Sergejs Svitnevs
Honored Contributor

Re: Perl Script help

Try to change:

for ( my $i=0; $i < $ntuples; $i++) {
@row = $sth->fetchrow; # Get a row
$row[0] = &clip($row[0]);
$distList .= "$row[0]; ";
}

to:

for ( my $i=0; $i < $ntuples; $i++) {
@row = $sth->fetchrow; # Get a row
$row[0] = &clip($row[0]);
if ($row[0]=~/Molly/ or $row[0]=~/Kim/) {
$distList .= "$row[0]; ";
}
}

Regards,
Sergejs
Ragni Singh
Super Advisor

Re: Perl Script help

After your recommendation, I have put the following entry as such. Now when I run it, I get the following error. Please help.

sub getDistList{
451 my $C = "select email from rpt_dist where rpt_id = '$_[0]';";
452 # die "$rptNam";
453 my $sth=$dbh->prepare($C);
454 if ( !defined $sth ) {
455 die "DML Error, Cannot prepare Dist List statement: $DBI::errstr";
456 }
457
458 if($sth->execute){
459 my $ntuples = $sth->rows;
460 if ($ntuples > 0) {
461 for ( my $i=0; $i < $ntuples; $i++) {
462 @row = $sth->fetchrow; # Get a row
463 $row[0] = &clip($row[0]);
464 if (row[0]=~/Molly/ or $row[0]=~/Kim/) {
465 $distList .= "$row[0]; ";
466 }
467 }
468 }

When I execute it as such..

perl secdaily.test, I get the following error..

syntax error at secdaily.test line 464, near "row["
syntax error at secdaily.test line 469, near "}else"
Execution of secdaily.test aborted due to compilation errors.
Ragni Singh
Super Advisor

Re: Perl Script help

Nevermind, it was a syntax error and I fixed it. Now when I run it tough, I get the following on my screen..

DIST_LIST:**

Before I made the chaange to add that statement, I was getting the following..

DIST_LIST:*msilva@pacificex.com; parmstrong@pacificex.com; bburke@pacificex.com; msilva@pacificex.com; parmstrong@pacificex.com; bburke@pacificex.com; *

Like I mentioned that what I want to do is be able to remove peter and bruce from the maillist. Also I woul dlike to add Tom to this list.

Thanks for the help.
Jess Long
Frequent Advisor

Re: Perl Script help

Sanjit:

It appears there is a typo on line 464. It reads "if (row[0]......" and should be "if ($row[0]..."

Hope this helps,
JL