Modern perl learning notes

Source: Internet
Author: User

The eq operator enforces the string context and treats its operations according to the string. = The operator forces the value context.

In rare cases, there is no suitable type operator, and you may need to explicitly force context. Force the value context and add zero before the variable. Forces the string context to concatenate variables and empty strings. Forces the Boolean context and uses the double negative operator.

My $ numeric_x = 0 + $ x; # force numeric Context
My $ stringy_x = ''. $ x; # force the string Context
My $ boolean_x = !! $ X; # force Boolean Context

 

In return for building and installing the release version by setting the CPAN client and the corresponding environment, you get access to the code library that can complete any task --

From database access to protocol analysis tools that can process almost all existing network devices, to sound and image processing libraries and package containers that share libraries on your system. # Maybe this is the advantage of Perl...

 

App::cpanminusIs an emerging CPAN client, aiming at speed, conciseness, and zero configuration. It is easy to install: # This is good

 $ curl -LO http://xrl.us/cpanm $ chmod +x cpanm

Even if you can declare a complex string through a series of embedded escape characters, it is more convenient to declare a multi-line character string across lines.HeredocThe syntax allows you to assign values to multiple strings in another way:

 my $blurb =<<'END_BLURB';
 He looked up. "Time is never on our side, my child. Do you see the irony? All they know is change. Change is the constant on which they all can agree.
 Whereas we, born out of time to remain perfect and perfectly self-aware, can only suffer change if we pursue it. It is against our nature.
 We rebel against that change. Shall we consider them greater for it?"
 END_BLURB

The clearest way to read files in Perl 5 is:
Use autodie;
Open my $ fh, '<', $ filename;
While (my $ line = <$ fh>)
{
Chomp $ line;
...
}


, $ @ Is a global variable. For the sake of security, you should use local to localize it before attempting to capture exceptions.
Value:
Local $ @;
# You may not be able to open the log file
My $ fh = eval {open_log_file ('monkeytown. log ')};
# Capture exceptions
If ($ @){...}

 

. From CPAN Try: Tiny release module is very short, easy to install
Installation, easy to understand, and easy to use:
Use Try: Tiny;
My $ fh = try {open_log_file ('monkeytown. log ')}
Catch {...};
Not only is the syntax more user-friendly than Perl 5 by default, but this module handles all sides and corners without your knowledge. # Again kneeling ....


A module is a package that contains its own files, can be loaded with use or require. A module must be a valid Perl 5
Code. It must end with a evaluate-worthy expression.


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.