Good Perl development habits

Source: Internet
Author: User

Summary:

1. Using built-in warning information

2. Using the Perl Help document

Details:
1. Built-in warning information
-Perl can warn you when there are "suspicious things" running in your program
-The warning does not change the behavior of the program, just as an auxiliary hint to the programmer. The programmer is prompted when Perl's interpreter considers the code to be problematic, but does not prevent the program from continuing
-the corresponding code should be modified until the warning is removed

2. How to turn on built-in warnings

-At run time, add the-w command line
Ex:perl-w My_program

-The program with the-w command line (recommended), in the code to specify the interpreter when the addition of-W, easy to use.
Ex: #! /usr/bin/perl-w

-For later versions of Perl 5.6, you can open them by warnings instructions. is to add the use warnings in the program code. Its use is more flexible, the default scope is the entire program, then the function and-W are the same.

If you are using relative to a piece of code, you can add use warnings to the code before the code, and then add no warnings to the line. It's only part of the action.
Use warnings

No warnings

-If you want to see a more detailed description of the problem, you can include it in the program:
Use diagnostics;

It will tell you why the interpreter is reporting this warning, and it may cause the program to become chaotic when used, so it is usually added when you do not understand the warning message.

-Use Strict
The built warning is not mandatory for the execution of the program. For beginners, use strict is recommended, especially if the program is very long, a page is not available, or the cause of the error is not found, and using strict forces the execution of the program to terminate until the prompt problem is resolved. It has two functions:

A. Avoid misspellings.

such as assigning a variable, but the use of the wrong number. Because Perl variables can be defined and used at any time, the interpreter does not error or warn. But the results of the program are not what you want.

B. Limiting the range of variables
This is especially useful in the case of calls with sub-programs. It can help us to assign the scope of the variables not easy to confuse

2. How to use the Help document Perldoc.

Perldoc can be installed with the interpreter when building Perl's development environment, not elsewhere. The perldoc contains the technical accumulation in use and

1) Help documentation is the best Perl learning material

2) When you encounter a function that you do not recognize, you should first query the Help document.

Ex:perldoc-f querying built-in functions
Perldoc-f print (returns the method and description of how the print function is used)
Perldoc-f Chmop (will return the use of functions, descriptions and related examples)

Ex:perldoc directly with the content to be queried
Perldoc Perlsync

(returns some description of the Perl syntax)

Ex:perldoc Perl

Will list all commands and commands that correspond to the meaning

This article refers to: Geek College Video: Good Perl development habits

Good Perl development habits

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.