In my Pearl code I have used the following two styles of writing that I have found later, disappointed in the modern Being Pearl:
# Style # 1: Using & amp; A user-defined sub-rootin & amp; Name_of_subroutine ($ some, $ something_else) before calling; # Style # 2: Using user ($ $) to show the number of arguments in user-defined sub-subname_off_subrantin ($$) {# one sub-method's body is taking two arguments}
Since learning, those styles are not recommended so I stopped using them.
However, with curiosity I want to know:
- What is the origin of those two types of writing? (I'm sure I have not dreamed of styles myself.)
- Why are two styles of writing discouraged in modern Pearl?
- Is these styles considered to be the best practice at some point in time?
and
sigil is usually two reasons for the modern pearl Function is not used in conjunction with calls. First of all, it is largely redundant because Pearl looks like a function (after the feet) as a function. Secondly, there is a big difference between the way the and the function ()
and and the functions
are executed, which can be confused for the less experienced Pearl programmer . In the first case, the function is not called any argument. In the second case, the function is called with the current @_
(and it can also change the logic list which will be seen by the later statements in that area:
print_and_remove_first_arg {print 'first arg:', shift, "\ n"} sub test {& print_and_remove_first_arg; print "remaining args: @_ \ n";} Exam 1, 2, 3;
First AGR: 1 remaining ARG: 2 3
Finally, and
Every function hides some and functions;
calls for calls, which search the bug In addition, by using & amp;
sigil, the function prototype, which can be useful in some cases (if you know what you are doing), But bugs can also be difficult to track, ultimately, & amp;
behavior is a powerful modifier to work, and that behavior should only be used.
Prototypes are identical, and they are used in modern Pearl Copy should be what should be clearly stated that no sign of the prototype functions in Perl they say to parse the calls within the same job functions made in the function indicates the compiler. That is, each symbol in the prototype asks the compiler to apply the context of that type of argument. While defining a function behaving like map
or push
or key
, this functionality can be very useful, all of which are a standard list operator In comparison, their first logic will behave differently.
sub my_map (& amp; @) {...} # First AG is either a block or a clear code reference my @ret = my_map {some_function ($ _)} is 1 .. 10;
Reason Sub ($$) {...}
and the use of prototype is frustrating because the author means "I want 9 times out of 10 Two arguments "and" I give two arguments to each with the scalar reference I put on the call site ". Pre-claim is better written:
Use carp; Sub need2 {@_ == 2 or cancer 'takes 2 logic 2'; ...}
which will allow the following calling style to work relatively:
my @ray = (2, 4); Need2 @ Array;
To sum, both the and
sigil and function prototypes are useful and powerful tools, but those functions should be used only when that functionality is required Ho. Their unnecessary use (or misuse of logic validation) is difficult to track countless behaviors and bugs.
Comments
Post a Comment