among 2007-2-27 11:22
关于perl中的疑问,请在此更贴提问!
[size=13px]请表述清楚!
本贴长期有效,尽量不要灌水,谢谢!
[/size][size=13px]::em71::[/size]
singwa 2007-3-8 14:01
木木,我使用perl来实现其它方面的问题也可以向你咨询吗?^_^
有一个这样的需求,根据提供的几个单词,查找一个文件,找到后修改该文件包含这几个单词的值。
(这个我在perl论坛上问过,得到的答案不是很好,虽然我现在实现了,但是通过生成一个新的文件来操作的,感觉有点笨。)
比如根据提供的@user=(liming zhangsan);
修改文件:
lisi : 19760715 jiangsu doctor active
liming : 19800623 fujian bachelor active
wangjun :19811205 beijing bachelor active
zhangsan : 19780612 hubei master active
查找liming,zhangsan并将最后的active改成inactive。
谢谢先!
i子休 2007-3-8 15:01
因为Perl语言本身并没有以行为单位的随机读写功能,所以同时操作两个文件是不可避免的
但是Tie::File模块封装了此类功能,可以考虑使用
另外,如果是二进制文件或者每行定长的文本文件,可以简单的使用seek来定位,而不用生成输出文件
x518889 2007-3-13 19:43
能不能给大家推荐一下比较好的perl介绍资料,我找了一下都不是很理想,不知道大家有没有,共享一下吧!
52702470 2007-5-21 17:24
找了篇——Perl 语言编程的PDF
找了篇——Perl 语言编程的PDF,
有十九章,内容比较多,
感兴趣的一起分享
blue_gugu 2007-5-22 16:08
请问:我有个邮件通知的trigger,英文comment可以正常显示,中文comment总是显示为乱码?怎样才能解决此问题呢?我用的是Net::SMTP 模块。
among 2007-5-28 16:15
回复 #9 blue_gugu 的帖子
使用mime
梦尘 2007-6-6 22:41
有人可以告诉我在哪里可以下载到perl吗?我在一些网站上下的运行不了。另外,可以告诉下怎么学习这个吗?我是想学点这个,但是没有任何编程基础!
somis 2007-6-9 01:34
perl是否需要到apache网站下载?在clearcase中如何使用?
blue_gugu 2007-6-21 12:05
回复 #9 among 的帖子
不知道among可以回复得详细一些么?是用哪个MIME模块呢?而且现在还有个问题,在clearcase安装后自带的ccperl中怎么添加模块呢?一直困惑中…………
谢谢帮助~~
happygod 2007-7-3 10:33
[quote]原帖由 [i]blue_gugu[/i] 于 2007-6-21 12:05 发表
不知道among可以回复得详细一些么?是用哪个MIME模块呢?而且现在还有个问题,在clearcase安装后自带的ccperl中怎么添加模块呢?一直困惑中…………
谢谢帮助~~ [/quote]
我的办法是:安装完perl的模块后把安装路径拷贝过去就可以用ccperl了
如:
cp -r /usr/lib/perl5/site_perl/5.8.5/Spreadsheet /opt/rational/common/lib/perl5/site_perl/5.8.6/
somis 2007-7-17 12:49
[quote]原帖由 [i]tommy[/i] 于 2007-7-17 09:53 发表
[url]www.perl.com[/url] [/quote]
谢谢!
现在找本 Perl的书真是难,查下网上书店,都是2003年以前的,基本都没有库存了。
somis 2007-7-18 15:19
[quote]原帖由 [i]x518889[/i] 于 2007-3-13 19:43 发表
能不能给大家推荐一下比较好的perl介绍资料,我找了一下都不是很理想,不知道大家有没有,共享一下吧! [/quote]
参见
[url]http://bbs.scmlife.com/thread-5675-1-1.html[/url]
提供几本Perl中文电子书
freelady 2007-9-11 22:11
share一份不错的perl文档
Learning Perl 3rd Edition, 跟大家share一下:)
freelady 2007-9-12 18:25
Perl语言入门
补充一个: Perl语言入门,这个是中文的。
[quote]原帖由 [i]freelady[/i] 于 2007-9-11 22:11 发表
Learning Perl 3rd Edition, 跟大家share一下:) [/quote]
ManUtd_Giggs 2007-9-20 22:40
perl 或者shell 编程都要学习啊 ,在UNIX下开发,整个环境还是需要一套的
winnie_yang 2007-12-27 10:30
回复 沙发 的帖子
Try, It works well on my PC. The content is stored in your file which is named "testfile.txt"
#!/usr/local/bin/perl
use warnings;
use strict;
my @TXT = ();
my @user = ();
my $line;
my $name1 = shift(@ARGV);
my $name2 = shift(@ARGV);
my $changed_line;
# `sed -i -e 's!active!inactive!g' testfile.txt`;
&search_name($name1, $name2);
#######################################################
sub search_name {
my($head1, $head2) = @_;
open (FH, "+<testfile.txt") || die ("cannot open the file\n");
@TXT = <FH>;
#print FH "nihao";
#print"wang yang 2: the content is $TXT[0]\n";
foreach $line(@TXT)
{
chomp($line);
open(FH2, ">>tempfile.txt") || die ("cannot open the temp file\n");
if ($line =~ m/$head1/i){
print"find the person $head1 in this file !\n";
print "The content of this line is: $line\n";
$line =~s/active/inactive/g;
# print " wang yang:$line\n";
print"####Go on continue to find other persons########\n\n";
$line .="\n";
print FH2 $line;
}
elsif ($line =~ m/$head2/) {
print"find the person $head2 in this file !\n";
print "The content of this line is: $line\n";
$line =~s/active/inactive/g;
$line .="\n";
print FH2 $line;
}
else {
print"Mismatch\n";
$line .="\n";
print FH2 $line;}
# my $curpos = tell(FH);
# seek(FH, $curpos, 0);
close FH2;
}
close FH;
system("rm -f testfile.txt");
system("mv tempfile.txt textfile.txt");
}