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;
}
# 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;
}
相关文章推荐
- Learning Perl: 8.9. A Pattern Test Program
- The example program of C on point
- The Perl Tutorial: Running a Perl Program (2)
- My first silly-dummy-crappy web-crawler perl program
- Do you still program in Perl?
- Java Program to print Prime numbers in Java - Example Tutorial and Code
- Installing perl and writing your first perl program in Ubuntu
- An Example of Perl Multi-thread 2
- C Java PHP Perl Python 的程序代码美化工具(Pretty Print Program/Source Code Beautifier)使用
- One example to understand SemFix: Program Repair via Semantic Analysis
- example program to process an idoc - inbound function module
- A easy example to tell you what is "2>&1" in Perl
- Inotify Example: Introduction to Inotify with a C Program Example
- Perl Regular Expressions by Example
- Hadoop example program code
- You need to install the perl-doc package to use this program.
- C Linked List Data Structure Explained with an Example C Program
- Matrix and linear algebra in F#, Part IV: profile your program, find the bottleneck and speed it up: using matrix multiplication as an example[z]
- Example of hash in Perl
- Program perl 数据结构