#! /usr/bin/perl
use strict;
use warnings;

print "\n----------------------------------_substitutions_with_s///--------------------------\n";
$_ = "He's out bowling with Barney tonight.";
s/Barney/Fred/;
print $_."\n";
s/filehandles/vertical_alignment/;
print $_."\n";
s/with (\w+)/against $1/;
print $_."\n";
print "\n----------------------------------_substitutions_with_s///--------------------------\n";

print "\n----------------------------------_/g--------------------------\n";
$_ = " xxx";
s/^\s+//;
print "<$_>\n";
$_ = "xxx   ";
s/\s+$//;
print "<$_>\n";
$_ = "    xxx   ";
s/^\s+|\s+$//g; # alternatives zeyipipei
print "<$_>\n";
print "\n----------------------------------_/g--------------------------\n";

print "\n----------------------------------_case_shifting--------------------------\n";
$_ = "I saw Cumulative with metHods.";
s/(cumulative|methods)/\U($1)/gi;
print "<$_>\n";
s/(cumulative|methods)/\L($1)/gi;
print "<$_>\n";
$_ = "I saw Cumulative with metHods.";
s/(\w+) with (\w+)/\U$2 with $1/;
print "<$_>\n";
s/(\w+) WITH (\w+)/\L$2 with $1/;
print "L:<$_>\n";
s/(\w+) with (\w+)/\u$2 with $1/g;
print "39: <$_>\n";
s/(cumulative|methods)/\u\L$1/g;
print "41: <$_>\n";
my $automating_sort = "factoring_out";
print "Hi \L\u$automating_sort\E, how are you?\n";
print "\n----------------------------------_case_shifting--------------------------\n";

print "\n----------------------------------_split_operator--------------------------\n";
my @globbing = split /:/, "homonyms:parentheses:reversing_lists";
print @globbing."\n";
my @variable_width_data = split /\s+/, "Mmap module preserving between sorts SHA values.";
print @variable_width_data;
print "\n";
$_ = "xxl Mmap module preserving between sorts SHA values.";
my @heredocs = split;
print @heredocs;
print "\n";
print "\n----------------------------------_split_operator--------------------------\n";

print "\n----------------------------------_join--------------------------\n";
my $caught_method = "-";
my $carp_module = join $caught_method, @globbing;
print $carp_module."\n";
my $charnames_module = join "chroot", "chunking";
print $charnames_module."\n";
print "\n----------------------------------_join--------------------------\n";

print "\n----------------------------------_m//_in_list_context_--------------------------\n";
 $_ = "class_hierarchies, demolition, autoload";
my($automating, $blessing, $objects) = /(\S+), (\S+), (\S+)/;
print $automating, $blessing, $objects;
print "\n";
my $text = "Fred dropped a 5 ton granite block on Mr. Slate";
my @words = ($text =~ /\w+/ig);
my @words___ = ($text =~ /[a-z]/ig);
print @words;
print "\n";
print @words___;
print "\n";
print "\n----------------------------------_m//_in_list_context_--------------------------\n";

print "\n----------------------------------_nongreedy_quantifiers--------------------------\n";
$_ = "I thought you said Fred and <BOLD>Velma</BOLD>, not <BOLD>Willa</BOLD>";
s#<BOLD>(.*?)</BOLD>#$1#g;
print $_."\n";
$_ = "I'm much better\nthan Barney is\nat bowling, \nWilma.\n";
print "Found 'Wilma' at start of line\n" if /^Wilma/im;
print "\n----------------------------------_nongreedy_quantifiers--------------------------\n";
=head1
print "\n----------------------------------_matching_multiple-line_text--------------------------\n";
open FILE, "< file_4_ex_ch7.txt"
    or die "cannot open file: $!";
my $lines = join '', <FILE>;
print $lines."\n";
$lines =~ s/^/file_4_ex_ch7.txt: /gm;
print $lines;
print "\n----------------------------------_matching_multiple-line_text--------------------------\n";

print "\n----------------------------------_updating_many_files--------------------------\n";
chomp(my $date = `date`);
$^I = ".bak";
while(<>){
    s/Author:.*/Author: Wei Yan/;
    s/^Phone.*\n//s;
    s/Date.*/Date: $date/;
    print;
}
print "\n----------------------------------_updating_many_files--------------------------\n";
=cut

print "\n----------------------------------_?=--------------------------\n";
my $string="I love chocolate ice.";
$string =~ s/chocolate(?= ice)/vanilla/;
print "$string\n";
print "\n----------------------------------_?=--------------------------\n";

print "\n----------------------------------_test1_triple_match--------------------------\n";
my $what = "string_evaluations";
$_ = "string_evaluationsstring_evaluationsstring_evaluations";
$what = "utilities|Mmap";
$_ = "utilitiesMmaputilitiesMmap";
if(/($what){4}/){
    print "$1 matched.\n";
}
print "\n----------------------------------_test1_triple_match--------------------------\n";

print "\n----------------------------------_--------------------------\n";

Perl语言入门:第九章 使用正则表达式处理文本 示例程序和代码的更多相关文章

  1. C语言入门---第九章 C语言指针

    没学指针就是没学C语言! 指针是C语言的精华,也是C语言的难点. 所谓指针,也就是内存的地址,所谓指针变量,也就是保存了内存地址的变量.不过人们往往不会区分两者的概念,而是混淆在一起使用. ===== ...

  2. Perl语言入门(中文版)(第6版) 东南大学出版社

    第一章简介 问题与答案 这本书适合你吗? 为何有这么多的脚注? 关于习题和解答? 习题前标的数字是什么意思? 如果我是Perl讲师? “Perl”这个词表示什么意思? Larry为什么要创造Perl? ...

  3. Perl 语言入门6-9

    ---- 第6章 哈希----------- 简介 键值对.键和值都是任意标量,但键总是会被转换成字符串. 键唯一,值可重复. 应用场景:一组数据对应到另一组数据时. 如找出重复/唯一/交叉引用/查表 ...

  4. Perl语言入门: 斜线不是元字符,所以在不作为分隔符时不需要加上反斜线。

    Perl语言入门: 斜线不是元字符,所以在不作为分隔符时不需要加上反斜线.

  5. Cesium入门2 - Cesium环境搭建及第一个示例程序

    Cesium入门2 - Cesium环境搭建及第一个示例程序 Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 验 ...

  6. Perl语言入门14-17

    ---------第十四章 字符串与排序------------------- index查找子字符串 my $stuff = "howdy world!"; my $where ...

  7. Perl语言入门

    Perl 是 Practical Extraction and Report Language 的缩写,可翻译为 "实用报表提取语言". Perl语法基础: (1)Perl程序由声 ...

  8. 深入理解Magento-第九章-修改、扩展、重写Magento代码

    (博主提示:本章应该不是原作者的第九章,仅作补充和参考) 作为一个开发者的你,肯定要修改Magento代码去适应你的业务需求,但是在很多时候我们不希望修改Magento的核心代码,这里有很多原因,例如 ...

  9. Perl语言入门:第六章习题:处理用户所指定的名字并汇报相应的姓。

    37 print "\n----------------------------------_exercise_6_1--------------------------\n";  ...

随机推荐

  1. css代码实现列表等宽

    实现上面的手机页面,我们会遇到一个自适应的问题,但是手机页面的屏幕大小不一致,自适应的问题不是百分比可以好好解决的,我采用下面的布局:display:flex; <!DOCTYPE html&g ...

  2. 2020/2/2 PHP代码审计之反序列化

    0x00 序列化与反序列化 序列化: serialize()把对象转换为字节序列的过程称为对象的序列化 反序列化: unserialize()把字节序列恢复为对象的过程称为对象的反序列化 0x01 序 ...

  3. 2020/1/30 PHP代码审计之文件上传漏洞

    0x00 漏洞简介 文件上传漏洞是指用户上传了一个可执行的脚本文件,并通过此脚本文件获得了执行服务器端命令的能力.这种攻击是最为直接和有效的,"文件上传"本身是没有问题,有问题的是 ...

  4. CentOS7使用firewalld的基本命令

    转自:https://www.cnblogs.com/moxiaoan/p/5683743.html.Thanks for  莫小安   1.firewalld的基本使用 启动: systemctl ...

  5. 简单模拟B1011

    #include<iostream> using namespace std; int main() { int n; long long a,b,c; cin >> n; ; ...

  6. 使用labelImg制作自己的数据集(VOC2007格式)用于Faster-RCNN训练

    https://blog.csdn.net/u011956147/article/details/53239325 https://blog.csdn.net/u011574296/article/d ...

  7. Kali桥接模式下配置动态ip

    以管理员身份运行虚拟机 打开 控制面板-->网络和Internet-->更改适配器 在虚拟机处桥接到这个WLAN2 点击 编辑-->编辑虚拟网卡 没有网卡就点上图的添加网络作为桥接网 ...

  8. elasticsearch-集群管理

    1.集群结构 ES 通常以集群方式工作.以提高搜索性能.容错能力.高可用.实现PB级数据搜索. 相关概念: (1)结点: ES集群由多台ES服务器组成.每个ES 服务端就是个一个NODE结点 (2)分 ...

  9. // 生成modbus CRC16数据

    CRC- / MODBUS : )CRC寄存器初始值为 FFFF:即16个字节全为1: )CRC- / MODBUS的多项式A001H ( 0001B) ‘H’表示16进制数,‘B’表示二进制数 计算 ...

  10. 三、VIP课程:并发编程专题->01-并发编程之Executor线程池详解

    01-并发编程之Executor线程池详解 线程:什么是线程&多线程 线程:线程是进程的一个实体,是 CPU 调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系 ...