In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what Perl variable naming rules are, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Variable naming rules in perl
Variable naming rules:
1. Do not have the same name as the built-in variable in perl, such as:% ARGV,$a,$b $_, etc.
Variable names in 2.perl are strictly case-sensitive
3. It is recommended to use a combination of uppercase letters, lowercase letters, numbers, and underscores to name variable names. Other special characters.
Example of variable naming
Variable names are named in the form of adjective _ noun, and multiple words are separated by an underscore, such as
$next_record$total_score$root_node
For the array or hash of the look-up table, use the naming method of xxx_of, xxx_for, that is, add a preposition at the end, for example.
My title_of;my ISBN_for;my @ sales_from
This way of writing makes the following code extremely readable.
While (my $month = prompt-menu = > $MONTH_NAMES) {for my $book (@ catalog) {print "$ISBN_for {$book} $title_of {$book}: $sales_from [$month]\ n";}}
For subroutines and methods, the grammar rules that make up names are as follows
Sub get_recordsub get_record_forsub eat_cookiesub eat_previous_cookiesub build_profilesub build_execution_profilesub build_execution_profile_using
In this way, there is little need to comment on the later code.
@ config_options = get_record_for ($next_client); for my $option (@ config_options) {build_execution_profile_using ($next_client, $option);} Boolean naming
It is generally named after the property or assertion being tested, which also makes conditional expressions read naturally. Generally speaking, most of these names start with is_ or has_, with exceptions, such as.
Sub is_valid;sub metadata_available_for;sub has_end_tag;my $loading_finished;my $has_found_bad_record
Take a look at the readability of the code that uses this rule, as shown below, which is almost self-annotated.
If (is_valid ($next_record) & &! $loading_finished) {METADATA:while (metadata_available_for ($next_record)) {pushu @ metadata, get_metadata_for ($next_record); last METADATA if has_end_tag ($next_record);}} else {$has_found_bad_record = 1;} reference variable naming
Adding _ ref to the end of the reference variable prevents it from being used as a normal variable.
Array and hash
Hashes are usually named singular, followed by prepositions, which have been mentioned earlier, while arrays are usually named plural.
Underline
The words of the name are separated by underlining.
Upper and lowercase
Subroutines, methods, variables, and tagged arguments are all lowercase.
Package and class names (IO::Controller) use mixed case.
Constants are capitalized ($SRC, $ARG).
Practical subroutine
When writing classes or modules, subroutines that are for internal use only and do not export should begin with an underscore
The above is all the content of the article "what are the naming rules of Perl variables?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.