neversaint has asked for the wisdom of the Perl Monks concerning the following question:
I was thinking if there is an efficient way to do this sort of thing on the fly? What I have now is simply storing them in hash. But it is very2 slow.prompt> perl check_filename.pl input_file.txt prompt> Files in our repos: file1.txt
#!/usr/bin/perl -w use strict; use File::Slurp; use File::Basename; my $input = $ARGV[0]; my @repos = glob("repos/*.txt"); # Store repos in hash my %hash; foreach my $repos_file (@repos) { my $text = read_file($repos_file); my $base = basename($repos_file,".txt"); $hash{$text} = $base; } # check input files: my $input_text = read_file($input); if ($hash{$input_text}) { print "File in our repos: $hash{$input_text}\.txt\n"; } else { print "no matching file\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficent Text Checking
by moritz (Cardinal) on Aug 27, 2007 at 13:26 UTC | |
|
Re: Efficent Text Checking
by liverpole (Monsignor) on Aug 27, 2007 at 13:35 UTC | |
|
Re: Efficent Text Checking
by archfool (Monk) on Aug 27, 2007 at 13:50 UTC |