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

I am performing an LDAP query on different containers read from a file. I have no problem performing this function on Perl 5.8, but when I put it on a different box with Perl 5.6 it simply doesnt read the second string from the file. I think it has something to do with the chomp.
while (<SUBNET>){ print $_; chomp $_; my $base = $_; print "test"; my $look = $ldap->search( base => $base, filter =>'(objectClass=dNIPIPAddressConfigu +ration)', attrs => ["dNIPAddressNumber", "dNIPHostNam +e", "dNIPLeaseExpiration", "dNIPLastUsed", "dNIPAssignmentTyp +e", "dNIPObjectReference"]);
So the first container works fine, but it then doesnt seem to read the next container. It will print the container, but it doesnt even reach the printed "test".

Replies are listed 'Best First'.
Re: strange LDAP bust
by duff (Parson) on Dec 22, 2003 at 17:20 UTC

    It may reach the "test" output but because of buffering you'll never see it. Set $|=1 for the STDOUT filehandle or use print "test\n"; instead (Outputting a newline often flushes the output buffer)

    That said, I think your problem is elsewhere than the chomp

Re: strange LDAP bust
by blue_cowdawg (Monsignor) on Dec 22, 2003 at 18:06 UTC

    Are you sure you are even opening the input file? It would seem to me that if you aren't even seeing "test" output to STDOUT then nothing is being read by the file handle <SUBNET> and therefore you are falling out of your loop prior to the prints.

    Given that you don't show how you are opening your file handle though I am just taking a S.W.A.G.

    Pressing just a little further, when you open your file handle are you catching error as in the following example:

      : : open (SUBNET,"< containers-in.txt") or die $!; : :
    and if you are what if any errors are you seeing?


    Peter L. Berghold -- Unix Professional
    Peter at Berghold dot Net
       Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.
      I am able to open the file without a problem. The search works for the first container, but fails for the rest. The same script worked fine on my other box. If I don't chomp the string, all the queries fail, but at least I see "test" printed

            I am able to open the file without a problem.
        OK. (digging a little deeper...) What happens when you do something like:
          #!/usr/bin/perl -w $|++; use strict; use warnings; use diagnostics; open(STUFF,"< containers.txt") or die "containters.txt:$!"; my @slurp=<STUFF>; close STUFF: chomp @slurp; printf "%s\n",join(",",@slurp);
        Are you seeing all your data?

        Another (random) thought: Are you checking error codes from LDAP?


        Peter L. Berghold -- Unix Professional
        Peter at Berghold dot Net
           Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.