#! /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. mybatis+mysql 通过sql脚本生成mapper的部分内容

    SQL mysql SELECT concat('<if test="', COLUMN_NAME, ' != null"> ', COLUMN_NAME, ',< ...

  2. UVA - 10934 Dropping water balloons(装满水的气球)(dp)

    题意:有k个气球,n层楼,求出至少需要多少次实验能确定气球的硬度.气球不会被实验所“磨损”. 分析: 1.dp[i][j]表示第i个气球,测试j次所能确定的最高楼层. 2.假设第i-1个气球测试j-1 ...

  3. 18 12 4 SQL 的基本 语法

    数据库的基本语法 -- 数据库的操作 -- 链接数据库 mysql -uroot -p mysql -uroot -pmysql -- 退出数据库 exit/quit/ctrl+d -- sql语句最 ...

  4. linux 安装禅道 和 CentOS 7 开放防火墙端口 命令

    linux 安装禅道链接:  https://www.cnblogs.com/maohuidong/p/9750202.html CentOS 7 开放防火墙端口 命令 链接:https://www. ...

  5. Java哪些集合类是线程安全的?

    早在jdk的1.1版本中,所有的集合都是线程安全的.但是在1.2以及之后的版本中就出现了一些线程不安全的集合,为什么版本升级会出现一些线程不安全的集合呢?因为线程不安全的集合普遍比线程安全的集合效率高 ...

  6. C语言历史

    如有错误,欢迎指出. 互帮互助,共同进步. 更新时间:2020-01-09 节选自<C语言程序设计现代方法>第2版 1.起源 C语言是贝尔实验室的Ken Thompson.Dennis R ...

  7. Codeforces 997A Convert to Ones(思维)

    https://codeforces.com/problemset/problem/997/A 题目大意: 给定一串0-1序列,定义两种操作: 操作一:选取一连续串倒置. 操作二:选取一连续串把进行0 ...

  8. one_day_one_linuxCmd---光标快捷操作

    <坚持每天学习一个 linux 命令,今天我们来学习 切换光标的常用命令> 摘要:最近经常使用 xshell 软件来远程连接各种机器,在 bin/bash 下输入各种命令,因为都是一些非常 ...

  9. Java并发分析—volatile

    在https://www.cnblogs.com/xyzyj/p/11148497.html中已经说明了在多线程并发的情况下,会出现数据的不一致问题,但归根结底就是一个原因,在宏观上就是线程的执行顺序 ...

  10. MySQL索引(一)

    1.索引的类型 1) B-Tree索引 (1)概念 人们常说的Mysql索引一般是指B-Tree索引,它使用B-Tree数据结构来存储数据.存储引擎以不同的方式使用B-Tree索引,性能也各有不同,各 ...