tux242 has asked for the wisdom of the Perl Monks concerning the following question:

Tux242 bites down hard on the bit to prepare for another flogging and loss of XP

Hello, I have a question about pulling from LDAP or metadirectories in the code below I am having problems pulling one of the attributes, fonManagerDN=cn, the cn is the end result of what I want from the fonManagerDN itself not the whole listing, can anyone tell me where I am going wrong? This is more or less a sub of a sub but I can not seem to get the syntax right. The rest of the attributes work fine.

@attr_list = ('cn','fonDeptName','telephoneNumber','l','st','fonManage +rDN=cn'); # print column header print LDAPFILE "InputValue:cn:fonDeptName:telephoneNumber:l:st:fonMana +gerDN=cn\n"; # ************** End of configuration section *********************** # ******************************************************************* # ************** Initialization ****************** # Set up a search pattern that will recognize any attribute. $attrs = join(':', @attr_list); # Create the global variables with an assignment to null. foreach $attr (@attr_list) { ${$attr} = ""; } #print "Bind using server $ldap_server and ID of $bind_dn\n"; # establish LDAP connection $ldap = Net::LDAP->new($ldap_server); unless ($ldap){ my $errmsg = $@; print STDERR "Failed to open LDAP session. Error = $errmsg\n"; exit; }

Replies are listed 'Best First'.
Re: pulling LDAP structure
by sauoq (Abbot) on Nov 21, 2003 at 00:12 UTC

    As for your question...

    # Create the global variables with an assignment to null. foreach $attr (@attr_list) { ${$attr} = ""; }

    Why are you doing that? Symbolic references are generally a no-no. You should probably be using a hash. That said, it shouldn't break anything.

    What is the problem you are actually having? Are you getting an error? Can you better explain exactly what the issue is?

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: pulling LDAP structure
by Roger (Parson) on Nov 21, 2003 at 00:30 UTC
    The first thing that you should do is to add "use strict;" to your program, as well as turning on warnings, this will catch most of the variable creation and typo errors. I have rewritten part of your script to make it more perl-ish.

    #!/usr/local/bin/perl -w use strict; my @attr_list = qw/ cn fonDeptName telephoneNumber l st fonManagerDN=cn /; # did you open the file? open LDAPFILE, ">ldap" or die "Can not create ldap"; # print column header print LDAPFILE "InputValue:", join(':', @attr_list), "\n"; close LDAPFILE; # ... # Set up a search pattern that will recognize any attribute. my $attrs = join '|', @attr_list; # <-- you probably want | instead o +f : ? # Create a hash with attribute names as search keys my %attrs = map { $_ => '' } @attr_list; # ... # ...
Re: pulling LDAP structure
by sauoq (Abbot) on Nov 21, 2003 at 00:04 UTC
    Tux242 bites down hard on the bit to prepare for another flogging and loss of XP

    Have you ever heard the phrase "self-fulfilling prophesy"?

    Really, now. You might take a step back and look at things with a broader perspective. XP is a number. On a website. It is not a measure of your intelligence. It is not a measure of your knowledge. It is not a measure of your appearance, your virility, or your chances for success in life. It is not a measure of your worth.

    Stop participating for the sake of XP and start participating for the sake of... well... participating. Once you do, your XP will probably climb anyway. (And, if it doesn't, you won't care, so it won't matter.)

    -sauoq
    "My two cents aren't worth a dime.";