您的位置:首页 > 其它

perl program example

2008-07-08 13:50 357 查看
#########################################################
# Search TargetFile Content from LookFile Content #
#########################################################

use strict;

die 'Usage: TargetFile LookFile ' unless @ARGV==2;

my $content1 = GetContentFromAFile( $ARGV[0] );
my $content2 = GetContentFromAFile( $ARGV[1] );

if( index($content2, $content1)>=0)
{
print "File $ARGV[1]/n/n contains /n/nFile $ARGV[0]";
}
else
{
print "File $ARGV[1]/n/n doesn't contain /n/nFile $ARGV[0]";
}

#################################
# Function #
#################################

sub GetContentFromAFile
{
die 'GetContentFromAFile Usage: FileName' unless @_==1;
my $content;

if(!open FILEHANDLE, "$_[0]")
{
die "Can't open file: $_[0]/n $!";
}

while(<FILEHANDLE>)
{
$content .= $_;
}

return $content;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: