perl split 的一种特殊用法
参考 http://blog.chinaunix.net/uid-1919528-id-2792055.html
split 函数的正规语法应该是:
split /PATTERN/, EXPR
而使用单引号(或者双引号)来分隔空格(whitespace)是一种特殊的例子:
As a special case, if the expression is a single space (" "), the function splits on
whitespace just as split with no arguments does. Thus, split(" ") can be used to
emulate awk ’s default behavior. In contrast, split(/ /) will give you as many null
initial fields as there are leading spaces. (Other than this special case, if you supply
a string instead of a regular expression, it’ll be interpreted as a regular expression
anyway.) -- Programming Perl
#!/usr/bin/perl -w
use strict;
my $test = "the first gap has two whitespace";
$_ = $test;
my $first = (split)[1];
my $second = (split(" ", $test))[1];
my $third = (split(/ /, $test))[1]; # 贪婪匹配,匹配尽量多的空格
print "\$first is $first\n"; # $first is first
print "\$second is $second\n"; # $second is first
print "\$third is $third\n"; # $third is
perl split 的一种特殊用法的更多相关文章
- String split方法与Guava Splitter用法区别
String split方法与Guava Splitter用法区别 今天同事写了一段使用String split方法的代码,如下所示,同事期望得到的是字符"1",但是没想到却得到空 ...
- js模版引擎handlebars.js实用教程——另一种Helper用法
返回目录 <!DOCTYPE html> <html> <head> <META http-equiv=Content-Type content=" ...
- 在 Perl看来, 字符串只有两种形式. 一种是octets, 即8位序列, 也就是我们通常说的字节数组. 另一种utf8编码的字符串, perl管它叫string. 也就是说: Perl只熟悉两种编
在 Perl看来, 字符串只有两种形式. 一种是octets, 即8位序列, 也就是我们通常说的字节数组. 另一种utf8编码的字符串, perl管它叫string. 也就是说: Perl只熟悉两种编 ...
- Linux下命令行cURL的10种常见用法示例
curl的命令行工具功能非常强大,这些数据交互的功能基本上都是通过URL方式进行的,下面这篇文章主要给大家分享了在Linux中命令行cURL的10种常见用法示例,通过示例代码介绍的非常详细,需要的朋友 ...
- 20190313 org.apache.commons.lang3.builder.EqualsBuilder的两种典型用法
org.apache.commons.lang3.builder.EqualsBuilder的两种典型用法 public boolean equals(Object obj) { if (obj == ...
- Linux上安装Perl模块的两种方法
Linux/Unix下安装Perl模块有两种方法:手工安装和自动安装.第一种方法是从CPAN上下载 您需要的模块,手工编译.安装.第二种方法是联上internet,使用一个叫做CPAN的模块自动完 ...
- @GeneratedValue 四种标准用法为TABLE,SEQUENCE,IDENTITY,AUTO.
一.JPA通用策略生成器 通过annotation来映射hibernate实体的,基于annotation的hibernate主键标识为@Id, 其生成规则由@GeneratedValue设定的.这里 ...
- 不可不看!CSS3中三十一种选择器用法
原文 The 30 CSS Selectors you Must Memorize 由 Jeffrey Way 发表于 2012 年 6 月,介绍了 30 种最常用的 CSS 选择器用法,多加了一种, ...
- java数组复制的几种常见用法
1.1数组复制的几种常见用法 1.1.1System.arraycopy的用法 int[] src = {1,3,5,7,9,11,13,15,17}; int[] dest = {2,4,6,8,1 ...
随机推荐
- js获取样式的兼容写法
var currentStyle = function(element){ return element.currentStyle || document.defaultView.getCompute ...
- http协议(九)响应首部字段
响应首部字段: 服务器向客户端返回响应报文中所使用的字段,用于补充的附加信息.服务器信息.以及对客户端的附加要求等 1.Accept-Ranges 告知客户端服务器能否处理范围请求,以指定获取服务器的 ...
- Kali linux渗透测试常用工具汇总1
1.ProxyChains 简介:代理工具.支持HTTP/SOCKS4/SOCK5的代理服务器,允许TCP/DNS通过代理隧道. 应用场景:通过代理服务器上网. 配置:/etc/proxychains ...
- JVM监测&工具[转]
通过工具及Java api来监测JVM的运行状态, 需要监测的数据:(内存使用情况 谁使用了内存 GC的状况) 内存使用情况--heap&PermGen @ 表示通过jmap –heap pi ...
- Meet Python: little notes
Source: http://www.liaoxuefeng.com/ ❤ Escape character: '\' - '\n': newline; - '\t': tab; - '\\': \; ...
- Java 集合系列06之 Vector详细介绍(源码解析)和使用示例
概要 学完ArrayList和LinkedList之后,我们接着学习Vector.学习方式还是和之前一样,先对Vector有个整体认识,然后再学习它的源码:最后再通过实例来学会使用它.第1部分 Vec ...
- 苹果系统里面部署ASP.NET
需要在global文件里设置一下 protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterCon ...
- [资料]自动化e2e测试 -- WebDriverJS,Jasmine和Protractor
1. http://sentsin.com/web/658.html 2. http://www.tuicool.com/articles/AnE3Mb 3. http://www.doc88.com ...
- Linux 信号详解六(可靠信号与不可靠信号)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...
- NOI2018准备Day19
5天没写. 伸展树 主席树 3到线段树模板题