In this article we learned how to sort strings or arrays of numbers in Perl.
Perl has a built-in function called sort. There is no doubt that you can sort an array. The simplest form is to pass an array that returns an array of sorted elements.
One, List
A list is a sequence of values enclosed in parentheses that can be any value or NULL, such as: (1, 5.3, "Hello", 2), empty list: ().
Note: A list containing only one numeric value (for example: (43.2)) is different from the value itself
Sort by Requirement:
Copy Code code as follows:
#!/bin/perl
@number =QW/5 10 15 3 2 4 8 6/;My @descending =sort {$a $b} @number; #这里 $a = 10, because $a was previously, the result of Perl was decimal in the previous, or ascending order.
The Perl programming language has a history of more than 26 years.
December 18, 1987 Larry Wall introduced the Perl programming language, and the first post to quote the language was in 88 January, from Google's discussion group: Perl, a
DBI: an APIthat connects all databases.DBD: is the DBI drive for different databases.Dbd::mysqlDBD::P GDbd::sqliteIf not , install with cpan .######################################################################DBI Interface:Customary
To re-assign each array element with a For loop:#!/usr/bin/perl@array = (1..30);p rint "@array \ n"; for ($i =0; $i Re-assigns each array element with a while loop:#!/usr/bin/perl@array = (1..30), $count = 1;print @array, while ($count Re-assigning
Python syntax is simple, and by indenting the way to express hierarchy, the code is very concise and easy to understand, for beginners, it is easier to get started.The pattern matching of Perl is very powerful, and there are many kinds of matching
Read standard input: in Perlforeach () {print "I saw $_";}The diamond operator <>: Its parameters are derived from the @argv array.The @argv array is checked first, and if it is empty, it is entered from the standard input stream. The value of the
Input and output: operator: Used to read data from STDIN:If you read the end of the file, the line input will return undef.$line = ; #读取下一行.Chomp ($line =); #去掉输入的一行的最后的换行符while () {print "$_";}foreach () {print "$_";}print function: used to output
You can decide if make the output shown on command screens by using 2>&1 or NULTesting script:print "without null \ n";System ("dir 2>&1");print "with null \ n";System ("dir > NUL");print "End \ n";Result:C:\rebecca\script\perl\unicode>perl
I. Condition statements:There are several types
1. If (condition expression) {statement block}
2. Single Perl statement if (conditional expression );
3. If (condition expression) {statement Block 1}
Else {statement Block 2}
4. If (condition
1. command line parameters in Perl:
Perl provides a special built-in array @ argv to store user input parameters from the command line. The function is the same as the command line parameters of C/C ++, but the implementation is not the same; the
In addition to alternative list implementations, the Library also offers other tools such asBisectModule with functions for manipulating sorted lists:
>>> Import bisect >>> scores = [(100, 'perl '), (200, 'tcl'), (400, 'lua'), (500, 'python')]>
Perl contains some predefined file handles. Such as standard input stdin, standard output stdout, and standard error stderr. The standard error stderr is an additional output path. How can we understand this sentence? Let's look at an example.% Perl-
1) grep function grep has two expressions: grep block listgrep expr, listblock represents a code block, usually represented by {}; expr represents an expression, usually a regular expression. In the original article, expr is anything, including one
Network programming is a mysterious and complex art, and of course it is also very interesting. The PERL language provides a wide range of TCP/IP network functions, all of which are directly derived from the C language socket library
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.