Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am trying to write some code that plays nicely with several different directory servers. I am using Net::LDAP. I am modifying several different directories at the same time, what is the preferred method of doing something like that?

############################################################# ## This sub will pass in an entry to be adjusted and a value ## to adjust with. It will only work on a single directory ## and a single task. ############################################################# sub add_dir_one{ my ($dn, $entry_to_modify) = @_; my $ldap = Net::LDAP->new($directory) or die "Couldn't connect: $@\n"; my $mesg = $ldap->bind("cn=directory manager, ou=a really long dn", +password => "password" ) or die "Could not bind $@\n";; $ldap -> modify ($dn, add => {attribute_to_be_adjusted => $entry_to_ +beadded}) or die "Ya screwed up again!";} } ############################################################# ## This sub will pass in an entry to be adjusted and a value ## to adjust with. It will only work on a second directory ## and a single task. ############################################################# sub add_dir_2{ my ($dn2, $entry_to_modify) = @_; my $ldap = Net::LDAP->new($directory2) or die "Couldn't connect: $@\n"; my $mesg = $ldap->bind("cn=directory manager2, ou=a really long dn", + password => "password2" ) or die "Could not bind $@\n";; $ldap -> modify ($dn2, add => {attribute_to_be_adjusted => $entry_to +_beadded}) or die "Ya screwed up again!";} }
or

############################################################# ## This sub will pass in an directory name, binding usre/password, ## action to be taken, entry to be adjusted and a value ## to adjust with. It will only work on a single directory ## and a single task. ############################################################# sub modify_generic_directory{ my ($dir, $dir_manager, $pass, $action_to_be_taken, $entry_to_be_adj +usted, $attribute_to_be_adjusted, $value_to_adjust_with) = @_; my $ldap = Net::LDAP->new($dir) or die "Couldn't connect: $@\n"; my $mesg = $ldap->bind($dir_manager, password => $pass) or die "Could not bind $@\n"; $ldap -> modify ($entry_to_be_adjusted, $action_to_be_taken => {$att +ribute_to_be_adjusted => $entry_to_be_adjusted}) or die "Ya screwed up again!";} }

and then calling each like this:

&add_dir_one($entry_to_modify, $variable_that_is_adjusting);<br> &modify_dir_two($entry_to_modify, $variable_that_is_adjusting);<br>
or
&modify_generic_directory($dir, $dir_manager, $pass, $action_to_be_tak +en, $entry_to_be_adjusted, $attribute_to_be_adjusted, $value_to_adjus +t_with);<br> &modify_generic_directory($dir2, $dir_manager2, $pass2, $action_to_be_ +taken2, $entry_to_be_adjusted, $attribute_to_be_adjusted, $value_to_a +djust_with);

I know there is not a single corect answer, I am just looking for guidelines.

"The social dynamics of the net are a direct consequence of the fact that nobody has yet developed a Remote Strangulation Protocol." -- Larry Wall


In reply to Subroutining for readability... by scottstef

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-19 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found