#! /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";

最新文章

  1. position:fixed和scroll实现div浮动【示例】
  2. lua 面向对象编程类机制实现
  3. iOS_XCode7_Launch Image 的初使用
  4. php代码优化系列 -- array_walk 和 foreach, for 的效率的比较
  5. 【代码笔记】iOS-改变导航条标题的颜色为红色
  6. 一步一步学swift之:自己写Api接口-PHP
  7. 大熊君说说JS与设计模式之------策略模式Strategy
  8. H5页面设计器,仿有赞商城页面在线设计器,比富文本框更友好的内容编辑器
  9. Delphi中如何将 Exe 程序或其他资料打包在内,使用时再释放使用(转)
  10. 使用libevent进行多线程socket编程demo
  11. c3p0写连接池 Demo
  12. 转发:为什么Android使用弱加密算法?
  13. tmd123.com
  14. ROWNUMBER()、RANK()、DENSE_RANK()、NTILE1
  15. mysql-关联查询
  16. Linux的sort命令
  17. react连连看
  18. 定时 清理 elasticsearch 6.5.4 的 索引 文件
  19. 继承:call、apply、bind方法
  20. BZOJ2124 等差子序列(树状数组+哈希)

热门文章

  1. mysql第三篇:表操作
  2. Day 6:Vector类和实现Hashset以及登录窗口的模拟
  3. 尝试用kotlin做一个app(二)
  4. C语言中getopt()和getopt_long()函数的用法
  5. blueimp,预览遮罩范围控制
  6. HTTPS(身披SSL协议的HTTP)
  7. 简单模拟B1001
  8. ZooKeeper解决的问题
  9. 数据类型操作简单对比(R和Python)
  10. 28. docker swarm 容器编排简介