Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help cleaning up inherited script

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I have a working script but it produces some warnings. In the interest of cleaning it up and learning a little more about perl, could someone advise me what is causing the errors?

Here is the script:
Code:
#!/usr/bin/perl -w

use Strict;
use Net::POP3;
use Authen::Krb5;
use Authen::SASL 2.10;
use Getopt::Long;
use Pod::Usage;

my ($user,$pass,$host,$help,$man);
my $del=1;

GetOptions('user=s' => \$user,
           'pass=s' => \$pass,
           'host=s' => \$host,
           'help'   => \$help,
           'delete!'=> \$del,  # for debug purposes
           'man'    => \$man) or pod2usage(2);

my $USERNAME=$user;
my $SERVICE="pop";
my $PASSWORD=$pass;
my $SERVER=$host;

pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
pod2usage(2) unless $user && $pass && $host;

my $ac=Authen::Krb5::init_context();
defined $ac or die "Fatal: Unable to establish Kerberos context\n";

my $clientp=Authen::Krb5::parse_name($USERNAME);
my $serverp=Authen::Krb5::sname_to_principal($SERVER,$SERVICE,KRB5_NT_SRV_HST);
my $cc=Authen::Krb5::cc_default();
$cc->initialize($clientp);

if (Authen::Krb5::get_in_tkt_with_password($clientp,$serverp,$PASSWORD,$cc)) {
        my $sasl=new Authen::SASL(mechanism=> "GSSAPI SASL");
        my $pop=Net::POP3->new($SERVER)
                or die "Unable to connect to mail server: ",$!,"\n";
	if ($pop->auth($sasl)) {
		my $messages=$pop->list()
			or die "Unable to get messages: ",$!,"\n";

		print "$user\@$host: ",scalar (keys (%$messages))," messages\n";

		foreach $num (keys (%$messages)) 
		{
			$pop->delete($num) if $del;
		}

		$pop->quit;
	}
	else {
		print "Authentication failed: ",$!,"\n";
	}
}
exit 0;
[/color green]
Here are the errors:

Subroutine bits redefined at /System/Library/Perl/5.8.6/strict.pm line 11.
Subroutine import redefined at /System/Library/Perl/5.8.6/strict.pm line 27.
Subroutine unimport redefined at /System/Library/Perl/5.8.6/strict.pm line 32.

Thanks.
 
use strict;" - note the lowercase 'S'. See if that helps any.
 
Thanks. That was it. It just took another pair of eyes. I never noticed that. Now for the tough question.

Why did that cause those errors rather then some kind of missing library error? TIA.
 
Maybe there is a Strict.pm as well in your directory structure?

Straw.Clutch=True;

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I assume you're probably running on Windows?

The filesystems used by Windows are case-insensitive. This means that when Perl looks for "Strict" (by trying to open a file called "Strict.pm" from @INC), it finds it. However, the file "Strict.pm" contains the "strict" package, not "Strict", so you'll get errors (since Perl is case-sensitive).

You'd get an error on Linux because it's case-sensitive.
 
You know what happens when you assume. :) I am running OS X. However, I think Apple provides their version of Unix file systems with case sensitivity turned off. That would mean your analysis is still applicable and likely explains the error. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top