Okay, after reading various documents online I have decided to try and write my code 
using -w and strict.

So here is the problem.  How do I pass Arrays to subs?  I assume declaring everything 
main:: would pretty much undermine the whole point of strict vars.  So... for example 
I have this sub which sends me mail if there is an error.

sub DieMsg
{
#Send mail to $admin in the event of an error
$diemessage = $_[0];

  open( MAIL, "|$mailprog -i -t" ) || die "Cannot open sendmail\n" ;
  print MAIL "To: $admin \n" ;
  print MAIL "From: Status Script <status\@foxjet.com> \n" ;
  print MAIL "Reply-to: $admin \n" ;
  print MAIL "Subject: Status Script Error\n" ;
  print MAIL "\n\n" ;
  print MAIL "$diemessage\n\n";
  print MAIL "--------------- HEADERS ---------------\n";
  print MAIL @headers;
  print MAIL "--------------- BODY ---------------\n";
  print MAIL @body;
  print MAIL "\n\n";
  close(MAIL);
  return 0 ;
}

Then in other parts of the program I have lines like...
$dbq = $query->execute or DieMsg("Error Inserting into Database: $query->errstr\n");

Of course this all goes to hell in a handbasket when I add -w and use strict.

I made a couple of scalars global that are used a lot (ie $main::admin) but otherwise 
can't figure out how to pass the info around.  I tried this...

sub DieMsg (@headers,@body)
{
#Send mail to $admin in the event of an error
my $diemessage = $_[0];

  open( MAIL, "|$main::mailprog -i -t" ) || die "Cannot open sendmail\n" ;
  print MAIL "To: $main::admin \n" ;
  print MAIL "From: Status Script <status\@foxjet.com> \n" ;
  print MAIL "Reply-to: $main::admin \n" ;
  print MAIL "Subject: Status Script Error\n" ;
  print MAIL "\n\n" ;
  print MAIL "$diemessage\n\n";
  print MAIL "--------------- HEADERS ---------------\n";
  print MAIL @headers;
  print MAIL "--------------- BODY ---------------\n";
  print MAIL @body;
  print MAIL "\n\n";
  close(MAIL);
  return 0 ;
}

But I still get
Global symbol "headers" requires explicit package name at ./status.pl line 21.

where line 21 is
  print MAIL @headers;

So I am hoping one of you use strict advocates on here will tell me where I am going 
wrong.

Thanks
Sheridan Saint-Michel

Reply via email to