what is wrong with my code
My guess is you need to refresh @store_array within the @first_directory loop
foreach my $first (@first_directory){
my @store_array = qw (1 2 3 4 5 6); # here
while(my ($i,$j) = splice(@store_array,0,2)){
my $second_directory = "$first/$i/$j";
..
try
#!/usr/bin/perl
use strict; use warnings;
use File::Glob 'bsd_glob';
my $store_location = '/path/to/file/store.txt';
open my $fh_log, '>', $store_location
or die "Fail to open file '$store_location' $!";
my $Dir1 = "/somewhere";
my $Dir2 = "/somewhereelse";
my @first_directory = ( $Dir1, $Dir2 );
foreach my $first (@first_directory){
my @store_array = qw (1 2 3 4 5 6 7 8);
while (my ($i,$j) = splice(@store_array,0,2)){
my $second_directory = "$first/$i/$j";
if (-e $second_directory and -d $second_directory){
my @files = bsd_glob("$first/$i/$j/*");
foreach my $file (@files){
my $lines = 0;
my $match = 0;
open(FILE, "<" , $file) or die "Can't open file '$file': $!";
+
while (<FILE>){
if (/TbhODK|octuov|qas_uop/) {
++$match;
}
++$lines;
}
print "$file : $lines lines read. $match matches found\n";
close FILE;
print $fh_log "File $file has $match matches\n";
}
} else {
print $fh_log "Directory $first/$i/$j (fail to exist)\n";
}
}
}
close $fh_log;
poj
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|