LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl NET::LDAP Help (https://www.linuxquestions.org/questions/programming-9/perl-net-ldap-help-4175542285/)

Kustom42 05-11-2015 01:26 PM

Perl NET::LDAP Help
 
Hey All,


I am working on a perl script to do some LDAP stuff and am running into an issue with my attrs LDAP value.

Here is my current subroutine that is giving me issues:

Code:

sub get_name_by_uid {
        my ($ldap, $userid, $base) = @_;
        my @Attrs = ();
        my $mesg = $ldap->search (
                base  => $base,
                attrs => [givenName, sn],
                filter => "(uid=$userid)" );
        if ($mesg->code == 0) {
                my $entry = $mesg->entry(0);

                if ($entry) {
                        return $entry;
                }
                else {
                        return undef;
                }
        }
        else {
                return undef;
        }
}

sub ldap_bind {
        my ($host, $dn, $password) = @_;

        my $ldap = Net::LDAP->new($host);
        my $mesg = $ldap->bind ($dn, password => $password);
        return $ldap if ($mesg->code == 0);
        return undef;
}


The error that I am getting is related to barewords in my attrs line on the get_name_by_uid subroutine:

Bareword "givenName" not allowed while "strict subs" in use at ./test.pl line 60, <DATA> line 522.
Bareword "sn" not allowed while "strict subs" in use at ./test.pl line 60, <DATA> line 522.


I can't seem to find a solution to this and am not a perl expert by any means.

I am trying to setup my subroutine to do an LDAP search with the $userid which is provided as an option to the script and return the givenName and sn LDAP attributes.


Thanks for any help you can provide!

Kustom42 05-11-2015 01:31 PM

Also, I know I can get around this by not using:

Code:

use strict;
But I want to know why this is happening and what I should be doing instead of using the barewords.

sundialsvcs 05-12-2015 07:19 AM

I cordially suggest that you take this question to http://www.perlmonks.org, a venerable specialty-site for Perl programming where you will get your required answers in minutes.


All times are GMT -5. The time now is 08:46 PM.