Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't think shift is bad. I find myself using it in a lot of code, especially modules that I write for office use. In some subroutines, I find myself using 3-5 shifts. In one of my modules (Student::Server), I've done this:
sub usr_create { my $DC; Win32::NetAdmin::GetAnyDomainController('','CLC', $DC); my $obj = shift; my $usr_log_file = shift; my $params = shift; if ( $obj->usr_log($usr_log_file,$params) ) { return 0; } my $usr = $obj->_rand_user(); if ( not Win32::NetAdmin::UsersExist($DC,$usr) ) { $obj->usr_add($usr); } else { $obj->usr_create($usr_log_file,$params); } }
Most people would probably frown upon that usage, but I like it. If I only need one parameter (per variable), then it's much easier to avoid confusion about parameters. In the above sub, I expect an object, a filename, and an array ref (which contains the order of logging parameters). In other words, a call to usr_create would look like: $obj->usr_create('test.txt', [Last_Name, First_Name, State]); or even  $obj->usr_create('test.txt', $aref); shift'ing out the necessary parameters avoids silly things like having a user pass too many arguments to the sub. In that case, anything not shift'ed out is discarded.

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

In reply to Re: Shift versus Sanity by Necos
in thread Shift versus Sanity by tadman

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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found