Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Perl variable

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use the Perl variable. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Understanding of Perl variables in Perl Learning Notes

Perl scalar learning

Any language has Perl variables. Perl variables are simply divided into scalar and group Perl variables in Perl.

Scalar: represents a single quantity, that is, the singular in English.

For example:

$name= "Hello"; $age=18; $price=123.88; $price=343_333_333.898

It is a scalar. Perl stores digital scalars in the form of floating-point numbers in the computer. Usually, the accuracy of floating point numbers is not accurate enough. This requires special attention.

Here is an example:

#! / usr/local/bin/perl $value=9.01e+21+0.01-9.01eroom21; print ("firstvalueis", $value, "\ n"); $value=9.01e+21-9.01eroom21O.1; print ("secondvalueis", $value, "\ n");-$program3_3 firstvalueis0 secondvalueis0.01

As you can see, different operation order may lead to different results! In Perl, a decimal number begins with 0x. 0 indicates an octal number. The operators of Perl for mathematical operations are:

Arithmetic operators: + (add),-(minus), * (multiply), / (divide), * * (power),% (remainder),-(monocular negative)

(1) needless to say about the first few. Talk about the power here need to register, the cardinality can not be negative.

(2) what does it mean to bear a single goal? He is actually a minus sign. It is the negative number representation in mathematics.

Arithmetic comparator for Perl variable:

= (equal), (greater than),! = (not equal), and one (indicating that three numbers can be taken-1)

In addition to being a number or string, scalars can also be references to other complex types. Please keep this in mind for the time being. I will explain this problem in detail later.

Now for strings, Perl uses unicode to represent a numeric value, which means that, like java, it can represent the language of any country in the world.

. (connected)

Comparators: lt (less than), gt (greater than), ne (not equal to), eq (equal to), le (less than or equal to), ge (greater than or equal to). The operation of a string is performed according to Ascii. That means a (ascii value is 97) and A (ASCII value is 65), and the result is: agtA

Another kind of Perl variable is called array Perl variable. as we all know, arrays represent a collection of data. data types can be divided into ordered arrays and unordered lists. It is usually equivalent to the plural in English. there is also a kind of hash. It is a special array. It is expressed in the form of Key+value. Equivalent to Map in Java. It is stored by pressing key-value pairs.

We use $to represent a scalar and @ to represent a list and array. Denote a hash with%.

Examples are as follows:

@ lines= ("a", "b", "c")

This defines an array with three elements abc and expands the intermediate elements with the () sign when defining the array. It is separated by a sign, or it can be written like this: @ lines=qw (abcd)

Note that when using the definition of qw, you cannot write a sign in it. Remember this!, and there can only be prototypes of characters in qw, for example, you give it like this: $a = "a"; @ lines=qw ($abcd)

Pass in the Perl variable $a, and that's what you're trying to do, but I'm telling you it won't work the way you want it to be.

He will show it to you intact. This also explains that you can't put a double quotation mark on abcd here.

% person represents a hash.

To give a value to this hash. Use $person {"name"} = "Hello"

You can also use the form% person= ("a", "b", "c", "d"). As we said, the hash represents a collection of key/value, so perl converts such a list of arrays to key/value. Every two groups, preceded by a key and followed by a value.

Of course, this form is not good-looking.

We can also write;% person= ("a" = > "b", "c" = > "d").

You can directly give the Perl variable represented by an array to a hash. With (), you can also point the specific value of one hash to another hash.

% person {"a"} = {

"name" = > "zhangsan"

"age" = > "23"

}

Access to zhangsan through $person {"a"} {"name"}

Not only that, you can point the specific value of a hash to a quantity.

% person {"a"} = ["A1", "a2", "A3"]

Access to A1 via $person {"a"} [0]

This is the end of this article on "how to use Perl variables". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report