perl push(请问下面perl脚本中的这条语句什么意思: $strPush =~ tr/\\x//d;)

本文目录
- 请问下面perl脚本中的这条语句什么意思: $strPush =~ tr/\\x//d;
- perl 语言高手请进~~~ 编程
- perl语言如何把程序输出的结果输入到一个数组里面去菜鸟求助~~~~
- perl push
请问下面perl脚本中的这条语句什么意思: $strPush =~ tr/\\x//d;
$strPush =~ tr/\\x//d;
语句的功能是对$strPush字符串的内容进行查找、替换,查找\x,替换为空,就是删除字符串里面的\x
标准的语句格式如下:
$s =~ tr/查找内容/替换内容/选项;
详细解释可以百度PERL TR
perl 语言高手请进~~~ 编程
答复补充:
你可以跑一下程序,看结果怎样
含标点符号也没问题,我原来以为这会影响单词数的统计,因为split分割一般不会用很复杂的语法,我这里只用了空白来分隔,但是又一想你又不需要得到每一个确切的单词,比如说文本中一行是: Hello World!那么数组中存的两个单词分别是 Hello和World!但单词统计仍不会出错。字符统计则统计的是包含标点符号的数目。
我写了段script,在我的机子上可以跑,如果你的txt中不含标点符号,这样就可以了,如果含标点则要修改script
Linux 上 在txt和script所在路径下用命令: parsetxt.pl txt1.txt txt2.txt
内容:
#!/usr/bin/perl
#for a zhidaoquestion
#Usage: parsetxt.pl txt1.txt txt2.txt
use strict;
use warnings;
($#ARGV == 1) || die "Usage: $0 《.txt file》 《.txt file》\n";
my $txt1 = $ARGV;
my $txt2 = $ARGV;
my @diff;
my @txt1;
my @txt2;
my $num_words1;
my $num_words2;
my $num_lines1;
my $num_lines2;
my $num_characters1;
my $num_characters2;
my $line;
open (TXT1, $txt1) || die "Can’t open input $txt1 file\n";
while (defined($line = 《TXT1》)){
chomp($line);
push (@txt1, $line);
my @words = split(/\s+/,$line);
my @characters = split(/\s*/,$line);
$num_words1 += scalar(@words);
$num_characters1 += scalar(@characters);
}
$num_lines1 = scalar(@txt1);
close TXT1;
open (TXT2, $txt2) || die "Can’t open input $txt2 file\n";
while (defined($line = 《TXT2》)){
chomp($line);
push (@txt2, $line);
my @words = split(/\s+/,$line);
my @characters = split(/\s*/,$line);
$num_words2 += scalar(@words);
$num_characters2 += scalar(@characters);
}
$num_lines2 = scalar(@txt2);
close TXT2;
my $minimum_lines = $num_lines1;
if ($num_lines2 《 $num_lines1) {
$minimum_lines = $num_lines2;
}
my $n;
for ($n=0; $n 《 $minimum_lines; $n++){
if ($txt1){
push (@diff, $n+1);
}
}
print "There’re $num_lines1 lines, $num_words1 words, $num_characters1 characters in the first file.\n";
print "There’re $num_lines2 lines, $num_words2 words, $num_characters2 characters in the second file.\n";
print "There differences in line @diff\n";
perl语言如何把程序输出的结果输入到一个数组里面去菜鸟求助~~~~
our @list=();
for($i=1;$i%2!=0 and $i《1000;$i++) {
print "$i\n";
push (@list, $i); #就是放入数组里是吧? push就可以了
$i++;
}
print @list;
perl push
大哥,你应该用更清楚的逻辑去看
首先,你看见的是一个push语句,它接受两个参数:第一个是一个array,那么就是“@{ }”这一部分;第二个是要push进去的元素,那么就是“\{ }”这一部分。
然后,你看见“@{ }”部分,它表示通过一个指向array的引用索取array。那么,不管{ }里面是什么,你就知道这里面一定是一个指向array的引用。
这个引用是什么呢?是$haxi{$arr}{’array’}。这个你应该能看懂吧?
接着,你看见“\{ }”部分,哪怕你不知道{ }里面是什么,你也会知道,要push进去的东西是一个指向匿名hash的引用的引用!(花括号表示指向匿名hash的引用,再取一个反斜杠表示引用的引用)
这个匿名hash是什么内容呢?是这样一个hash:(’S’=》$arr-1
这不就完了吗?

更多文章:
随机挑战用的软件(有没有什么软件是可以随机抽题的呢现在我们有需求把一个EXCEL的题库里面随机抽出50道题)
2026年8月28日 20:15
html滚动条好看的样式(HTML如何实现某区域的内容用滚动条看,其它区域都是固定不动的)
2026年1月2日 14:45
易语言源码缺模块(易语言缺少编译模块,无法编译,我想要个独立的静态编译器)
2026年5月13日 20:15
php小项目开发(如何使用Zend Studio创建PHP项目)
2026年7月23日 02:30
中高端女包品牌有哪些牌子?十大全球品牌女包排行榜(包包牌子有哪些)
2025年9月11日 17:15
关于springmvc和struts2(Spring MVC和Struts2有什么区别)
2026年7月15日 09:00
chargeoff是什么意思(Charge Off是什么意思)
2025年12月6日 12:30
oracle判断是否包含某个字符串(如何查询一个oracle数据库中所有表的所有字段哪个包含特定字符串)
2025年12月1日 06:30
怎么进入web登录(juniper路由器怎么开启web登录)
2026年8月21日 13:00
dev出现makefile是什么情况(c语言编译运行出现Makefile.win已经改变,怎么改)
2025年10月1日 01:30
用excel多位随机数生成器(excel自动随机生成多位数)
2025年11月4日 07:45












