Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Subroutining for readability...

by runrig (Abbot)
on Nov 09, 2001 at 00:15 UTC ( [id://124163]=note: print w/replies, xml ) Need Help??


in reply to Subroutining for readability...

I would tend to use the second option. I think explicitly passing in args, having as few globals as possible, and having to write fewer subroutines would be a good thing. But its not the only options. You could go OO and hide all the parameters in, e.g. a hashref and just call the subs as methods, like  $dir_server->modify_directory. Or you could use closures to write the subs with some fixed parameters for each directory server, and leave the rest as args to pass in.

Looking at the docs, the new() method is the only one that returns undef and returns an error message in $@; for the rest, you have to examine the returned Message object. An OO example:

package DirServer; sub new { my $class = shift; my ($dir, $dir_manager, $pass) = @_; my $ldap = Net::LDAP->new($dir) or die "Couldn't connect: $@\n"; my $result = $ldap->bind($dir_manager, password=>$pass); $result->code && die "Couldn't bind".$result->error; bless \$ldap, $class; } sub modify_directory{ my $ldap = ${shift()}; my ($action_to_be_taken, $entry_to_be_adjusted, $attribute_to_be_adjusted, $value_to_adjust_with) = @_; my $result = $ldap -> modify($entry_to_be_adjusted, $action_to_be_taken => {$attribute_to_be_adjusted => $entry_to_be_adjusted}); $result->code && die "Ya screwed up".$result->error; } # Then... package main; my $dir_server = DirServer->new(@args); $dir_server->modify_directory(@more_args);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found