Hi RenMcCourtey,
While what you want to do could be done with a oneliner*, as the code gets more complex it's certainly advisable to use the proper tools for the job.
Apparently ldapsearch outputs in LDIF format, which can be read by, for example, Net::LDAP::LDIF. Here's a quick example I whipped up using the documentation, its output looks like what you want:
use Net::LDAP::LDIF;
my $ldif = Net::LDAP::LDIF->new('nejms.txt', 'r', onerror=>'die');
while (!$ldif->eof) {
my $entry = $ldif->read_entry;
print $entry->get_value('cn'), "=",
$entry->get_value('orclnetdescstring'), "\n";
}
$ldif->done;
If it's an option for you, you could maybe use Net::LDAP for all your work. (Disclaimer: I don't have experience with the module. It does have a long release history and good reviews, though.)
* I'd strongly recommend the above instead, this is just an example of one way to do it:
$ perl -ne 'next if /^dn:|^\s*$/; s/^cn:\s*(.+)\n/$1/;
s/^orclnetdescstring:\s*/=/; print' nejms.txt
common_name1=complex_address_line1
common_name2=complex_address_line2
common_name3=complex_address_line3
Hope this helps, -- Hauke D |