Skip to content

Instantly share code, notes, and snippets.

@hlapidez
Forked from blaxter/ldap filter pretty print
Created February 10, 2022 10:35
Show Gist options
  • Save hlapidez/8acb315e639e061fef6c864d6ebdf3f0 to your computer and use it in GitHub Desktop.
Save hlapidez/8acb315e639e061fef6c864d6ebdf3f0 to your computer and use it in GitHub Desktop.
ldap filter pretty print
#! perl -slw
use strict;
( my $input = do{ local $/; <DATA> } ) =~ tr[\n][]d;
my $tab = 0;
$input =~ s[([()])]{
$tab-- if $1 eq ')';
my $modified = "\n" . ( " " x $tab ) . $1;
$tab++ if $1 eq '(';
$modified;
}ge;
$input =~ s[\n\s+\)][)]g;
print $input;
__DATA__
(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=
user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(obje
ctClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)
(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(obj
ectCategory=msExchDynamicDistributionList) ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment