计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数

计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数_第1张图片

Perl是一种主要用于开发web应用程序的编程语言。Perl是一种解释语言,而不是编译语言。这意味着它的程序比编译语言占用更多的CPU时间——随着处理器速度的提高,这个问题变得不那么重要了。用Perl编写代码比用编译语言编写要快,所以节省的时间是您自己的。当您学习Perl时,您将学习如何使用该语言的函数。最基本的函数之一是字符串长度函数。

Perl is a programming language used primarily to develop web applications. Perl is an interpreted, not compiled, language. This means its programs take up more CPU time than a compiled language

— a problem that becomes less important as the speed of processors increases. Writing code in Perl is faster than writing in a compiled language, so the time you save is yours. When you learn Perl, you learn how to work with the language's functions. One of the most basic is the string length function.

计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数_第2张图片

如何在Perl中查找字符串的长度 How to Find Length of a String in Perl

Perl的length函数以字符为单位返回Perl字符串的长度。下面是一个例子,展示了它的基本用法: Perl's length function returns the length of a Perl string in characters. Here is an example showing its basic usage:

计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数_第3张图片

执行此代码时,将显示以下内容: “字符串长度为:27。”数字“27”是短语“This is a Test and ALL CAPS”中的字符总数,包括空格。

When this code is executed, it displays the following: "Length of the String is: 27."The number "27" is the total of the characters, including spaces, in the phrase "This is a Test and ALL CAPS."

计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数_第4张图片

注意,这个函数不以字节为单位计算字符串的大小,而以字符为单位计算长度。Note that this function does not count the size of the string in bytes — just the length in characters.

数组的长度呢? What About the Length of Arrays?

length函数只对字符串有效,对数组无效。数组存储有序列表,前面有@符号,并使用圆括号填充。要计算数组的长度,请使用标量函数。例如:

my @many_strings = ("one", "two", "three", "four", "hi", "hello world");say scalar @many_strings;

The length function works only on strings, not on arrays. An array stores an ordered list and is preceded by an @ sign and populated using parentheses. To find out the length of an array, use the scalarfunction. For example:

计算机科学中的空串,双语速读:计算机科学-Perl字符串长度函数_第5张图片

应数是“6”,即数组中的项数。标量是数据的单个单位。它可以是一组字符,如上面的示例所示,也可以是单个字符、字符串、浮点数或整数。

The response is "6," the number of items in the array. A scalar is a single unit of data. It might be a group of characters, as in the example above, or a single character, string, floating point, or integer number.

注明图片及英文均来源于网络,若侵权请告知作者删除!

举报/反馈

你可能感兴趣的:(计算机科学中的空串)