perl 数组grep

The Perl grep() function is a filter that runs a regular expression on each element of an array and returns only the elements that evaluate as true. Using regular expressions can be extremely powerful and complex. The grep() functions uses the syntax @List = grep(Expression, @array).

Perl grep()函数是一个过滤器,它在数组的每个元素上运行正则表达式,并且仅返回评估为true的元素。 使用正则表达式可能非常强大和复杂。 grep()函数使用语法@List = grep(Expression,@array)。

使用Grep()函数返回真表达式 ( Using Grep() Function to Return True Expressions )


@myNames = ('Jacob', 'Michael', 'Joshua', 'Mathew', 'Alexander', &


@grepNames = grep(/^A

Think of the @myNames array as a row of numbered boxes, going from left to right and numbered starting with a zero. The grep() function goes through each of the elements (boxes) in the array and compares their contents to the regular expression. If the result is true, the contents are then added to the new @grepNames array.

将@myNames数组视为一排带编号的框,从左到右并从零开始编号。 grep()函数遍历数组中的每个元素(框),并将其内容与正则表达式进行比较。 如果结果为true ,则将内容添加到新的@grepNames数组中。

In the above example, the regular expression /^A/ is looking for any value that starts with a capital A. After sifting through the contents of the @myNames array, the value of @grepNames becomes ('Alexander', 'Andrew'), the only two elements that start with a capital A.

在上面的示例中,正则表达式/ ^ A /正在查找以大写字母A开头的任何值。在@myNames数组的内容中进行筛选后,@ grepNames的值变为('Alexander','Andrew') ,只有两个以大写字母A开头的元素。

反转Grep()函数中的表达式 ( Reversing the Expression in a Grep() Function )

One quick way to make this particular function more powerful is to reverse the regular expression with the NOT operator. The regular expression then looks for elements that evaluate to false and moves them into the new array.

使此特定功能更强大的一种快速方法是使用NOT运算符反转正则表达式。 然后,正则表达式将查找结果为false的元素,并将其移动到新数组中。


@myNames = ('Jacob', 'Michael', 'Joshua', 'Mathew', 'Alexander', &


@grepNames = grep(!/^A

In the above example, the regular expression is looking for any value that does not start with a capital A. After sifting through the contents of the @myNames array, the value of @grepNames becomes ('Jacob', 'Michael', 'Joshua', 'Matthew').

在上面的示例中,正则表达式正在寻找不以大写字母A开头的任何值。在@myNames数组的内容中进行筛选后,@ grepNames的值变为('Jacob','Michael','Joshua ', '马修')。

关于Perl ( About Perl )

Perl is an adaptable programming language frequently used to develop web applications. Perl is an interpreted, not compiled, language, so its programs take up more CPU time than a compiled language—a problem that becomes less important as the speed of processors increases. However, writing in Perl is faster than writing in a compiled language, so the time you save is yours.

Perl是一种经常用于开发Web应用程序的适应性编程语言。 Perl是一种解释性而非编译语言,因此它的程序比编译语言占用更多的CPU时间-随着处理器速度的提高,此问题变得不那么重要了。 但是,用Perl编写要比用编译语言编写要快,因此节省的时间就是您自己的。

翻译自: https://www.thoughtco.com/perl-array-grep-function-quick-tutorial-2641158

perl 数组grep

perl 数组grep_Perl数组Grep()函数相关推荐

  1. [码海拾贝 之Perl]在字符串数组中查找特定的字符串是否存在

    前言 检索一个字符串是否存在于一个数组中, 最基本的想法应该就是对数组进行循环, 逐个判断数组的每个元素值和给定的值是否相等. (在Java语言还可以把数组转成 List , 在 list 中直接有 ...

  2. perl中的grep函数介绍

    31 grep函数 (如果你是个的新手,你可以先跳过下面的两段,直接到 Grep vs.loops 样例这一部分,放心,在后面你还会遇到它) <pre> grep BLOCK LIST g ...

  3. php 打印对象详细信息,php打印显示数组与对象的函数详解

    php打印显示数组与对象的函数详解 发布于 2014-11-17 18:55:49 | 699 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertext P ...

  4. perl 哈希数组的哈希_使用哈希检查两个数组是否相似

    perl 哈希数组的哈希 Prerequisite: Hashing data structure 先决条件: 哈希数据结构 Problem statement: 问题陈述: Check whethe ...

  5. perl 哈希数组的哈希_第一个元素使用哈希在数组中出现K次

    perl 哈希数组的哈希 Prerequisite: Hashing data structure 先决条件: 哈希数据结构 Problem statement: 问题陈述: Find the fir ...

  6. [译]Perl中的数组

    原文:http://perl5maven.com/perl-arrays 在本篇Perl教程中,我们将会学习Perl中的数组.本文只是对Perl中的数组进行了一下概述,在以后的文章中,我们还会更加详细 ...

  7. perl数组硬引用_Perl基础 Perl引用和数组用法解析

    本文和大家重点讨论一下Perl引用和数组的概念,Perl5中的两种Perl引用类型为硬引用和符号引用.符号引用含有变量的名字,它对运行时创建变量名并定位很有用,基本上,符号Perl引用就象文件名或UN ...

  8. C++ 笔记(14)— 指针(指针声明、取地址、取值、new/delete、NULL指针、指针运算、指针数组、数组指针、指针传递给函数、从函数返回指针)

    1. 声明指针 指针是一个变量,其值为另一个变量的地址,即,内存位置的直接地址.就像其他变量或常量一样,您必须在使用指 针存储其他变量地址之前,对其进行声明. 指针变量声明的一般形式为: type * ...

  9. Go 学习笔记(10)— 数组定义、数组声明、数组初始化、访问数组、数组相等、向函数传递数组

    1. 数组定义 数组是具有相同唯一类型的一组已编号且长度固定的数据项序列,这种类型可以是任意的原始类型例如整形.字符串或者自定义类型. 2. 声明数组 Go 语言数组声明需要指定元素类型及元素个数,语 ...

最新文章

  1. php导入excel表格数据,php页面导入excel表格数据-php导入excel 怎么获取excel表格数据...
  2. s3c2410_gpio_cfgpin函数解析
  3. c# webservice生成客户端及使用时碰到decimal类型时的特殊处理
  4. Mysql远程无法连接
  5. python3 exe_Windows10下python3和python2同时安装 python2.exe、python3.exe和pip2、pip3设置
  6. 柏林的评委还识货,我的打赌也算是赢了
  7. BZOJ1500 [NOI2005]维修数列(Splay tree)
  8. 对pca降维后的手写体数字图片数据分类_知识干货-机器学习-TSNE数据降维
  9. 4,GIL全局解释器锁,event事件,信号量
  10. 由浅入深解释JS执行机制 EventLoop
  11. 尚学堂科技_王勇_JAVA视频教程_Hibernate
  12. (转)详解HTML网页源码的charset格式
  13. 【数据结构之旅】循环队列
  14. 剪映怎么把英文字幕翻译成中文?(附视频教程+字幕翻译工具)
  15. 【LeetCode - 379】电话目录管理系统
  16. 最全超实用的网站SEO优化方案步骤解析
  17. 一个网站完整的SEO优化方案
  18. mysql 给表添加唯一约束、联合唯一约束,指定唯一约束的名字
  19. 轩辕Linux开放实验室
  20. 上半年净利同比降46%,依赖大客户的天润云能靠IPO翻身吗?

热门文章

  1. Proteus仿真STM32的课设实例3——汽车倒车测距提示仪
  2. [文摘20070914]一个成功的博客必须知道的80个博客工具
  3. 2022考研复试时间轴及注意事项!重要哟!
  4. module “**.vue“ has not default
  5. Excel的宽度怎么算的?
  6. 值得一生收藏的经典台词(轉)
  7. VS2022 scanf返回值被忽略怎么办
  8. CancelledError: [_Derived_]RecvAsync is cancelled.
  9. CMS 触发GC(Allocation Failure)解析之标梵信息
  10. Android 显示刷新机制、VSYNC和三重缓存机制