Hi Wim

> Hi Bob,
>
> You gave me the following answer earlier:
>
>    sub foo {
>
>       local @ARGV = @_;
>       GetOptions(...blah...);
>
>       ...
>    }
>
> If I run it as a seperate script, commenting out the (local @ARGV = @_;)
> line, then it works.  But it does not work when called as a subroutine from
> within the main script. 

Can you be more specific about "does not work" and "called ... from within the 
main script"?

Your code below is not a functional example, so I made some changes
(especially inserting "use strict" and "use warnings" which alway gives good 
hints :-), 
and it works - but maybe in the sense you mentioned that it works for you too:

=== begin script (test3.pl) ===
use strict; use warnings;
use Getopt::Long;

sub notify_email {
  local @ARGV = @_;

  my (@recipients, @subject, @body);
  my %conf=(smtp=>'whatever', smtpsender=>'something');

  $ENV{"NTsendmail"}  = $conf{'smtp'};
  my $sender             = $conf{'smtpsender'};

  GetOptions ("r=s"  => [EMAIL PROTECTED],
              "s=s"  => [EMAIL PROTECTED],
              "b=s"  => [EMAIL PROTECTED]);
  my $subject    = join(" ", @subject);
  my $body       = join(" ", @body);

  foreach my $recipient (@recipients) {
    print "$sender, $recipient, $subject, $body\n";
#    $mail = new NTsendmail;
#    $mail->send($sender, $recipient, $subject, $body);
  }
}

notify_email (@ARGV);
=== end script ===

This prints:

something, rrrr, sss, bbbb


> I have also tried (my @ARGV = @_;). 
> Any idea why?
>
> Here is my code now:
> =================================================
> # Notify recipients via SMTP (email)
> # Usage: notify_email -r [EMAIL PROTECTED] -r [EMAIL PROTECTED] -s "Subject 
> line" -b
> "Message body"
> sub notify_email {
>   local @ARGV = @_;   # Get the sub's params into the master param array
> for GetOpt::Long
>   $ENV{"NTsendmail"}  = $conf{'smtp'};
>   $sender             = $conf{'smtpsender'};
>
>   GetOptions ("r=s"  => [EMAIL PROTECTED],       # -r [EMAIL PROTECTED] -r 
> [EMAIL PROTECTED]
> -r [EMAIL PROTECTED]
>               "s=s"  => [EMAIL PROTECTED],          # -s "This is the subject
> line..."
>               "b=s"  => [EMAIL PROTECTED]);            # -b "This is the 
> message
> body..."
>
>   $subject    = join(" ", @subject);
>   $body       = join(" ", @body);
>
>   foreach $recipient (@recipients) {
>     print "$sender, $recipient, $subject, $body\n";
>     $mail = new NTsendmail;
>     $mail->send($sender, $recipient, $subject, $body);
>   }
> }
> =================================================
>
> ___________________________________________________________________________
>_______________________________________________________
>
> Standard Bank Disclaimer and Confidentiality Note
[...]


hth, joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to