Perl beginner here. I have an existing code, that was written some years ago. Basically, the code is used to peruse a database of names, and extract certain ones, based on their roles. That part works fine. Occasionally, I want to exclude certain names, so this script is supposed to reference an exclusion file. This is where it goes south. I get no errors, so it's like it can "see" the file, but doesn't actually read it. Obviously, it would be helpful to learn Perl, so I know what I am doing, and understand it; but for the short term I'd like to just fix the problem that is occurring. I shall attempt to paste my code. I have no idea what OS it was originally written on, but was used on rhel 6, and is now on a rhel 7 server. My guess as to why it no longer works, is because the current version of perl is newer, and so the code doesn't quite work the same. I currently have 5.16.3, which isn't exactly new, either. I've tried debugging, but I get no errors, at least nothing that stands out as an error.
#!/usr/bin/perl -w use strict; use Net::LDAP; use Time::Piece; if ($#ARGV < 0) { print STDERR "Usage: ./everyone.pl pwd\n"; exit 1; } my $host = "ldap1.server.com:1000"; my $bindcred = $ARGV[0]; my $binddn = "cn=Directory Manager"; my $basedn = "ou=People,dc=server,dc=com"; my $dateout = Time::Piece->new->strftime('%Y%m%d'); my $infile = "output/$dateout/everyone.list"; open(OUTFILE, ">", $infile) or die("Can't open $infile.clean for outpu +t"); my $ldap = Net::LDAP->new($host, timeout=>2) || SYSerror("New", "Couldn't connect to $host"); my $mesg = $ldap->bind("$binddn", password=>"$bindcred"); if ($mesg->is_error) {LDAPerror("Bind", $mesg);} my $result = $ldap->search(base=>"$basedn", scope=>"sub", filter=>"(&(|(servercomBannerRole=Student)(servercomBannerRole=Facul +ty)(&(servercomBannerRole=Staff)(!(servercomBannerRole=Villagestaff)) +)))", attrs=>["mail","cn"]); if ($result->is_error) {LDAPerror("Search", $result);} my @entries = $result->entries; my $mExcludingFile = "excludes/everyone.txt"; my $includingFile = "includes/everyone.txt"; my @mArray = (); my $mLine; my $mCountAll = 0; my $mCountOrig = 0; my $mCountAdd = 0; my $mCountDel = 0; open(ROFILE, "<", $mExcludingFile) or die("Can't open $mExcludingFile +exception file!"); while(<ROFILE>) { push(@mArray, $_); } close(ROFILE); my $mArrayNow; my $entry; foreach $entry(@entries) { my $name = $entry->get_value("cn"); my $email = $entry->get_value("mail"); my $mLineNow = "$email $name\n"; my $mOkay = 1; $mCountOrig++; foreach $mArrayNow (@mArray) { if ($mLineNow eq $mArrayNow) { $mOkay = 0; } } if ($mOkay == 1) { print OUTFILE $mLineNow; } else { $mCountDel++; } } flock(OUTFILE, 8); close(OUTFILE); open(OUTFILE, ">>", $infile); open(EXCEPTF, "<", $includingFile) or die("Can't open $includingFile i +nclusion file!"); while(<EXCEPTF>) { print OUTFILE $_; $mCountAdd++; } flock(OUTFILE, 8); close(OUTFILE); close(EXCEPTF); $mCountAll = $mCountOrig + $mCountAdd - $mCountDel; print "Ok.. Generated ".$mCountAll." (".$mCountOrig." + ".$mCountAdd. +" - ".$mCountDel.")\n"; sub LDAPerror { my ($from, $mesg) = @_; print "Error: " . $mesg->code . " (" . $mesg->error_name . ")\n"; print $mesg->error_text . "\n"; } sub SYSerror { my ($from, $mesg) = @_; print "Error: $mesg\n"; print "Source: $from\n"; die "$@"; }

In reply to script runs, but doesn't appear to call file by schwende

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.