http://qs321.pair.com?node_id=1224232

MissPerl has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks! CODE EDITED

I want to go into first directory/i/j/*, then read all the files and all the lines inside every file. Eg, /somewhere/1/2/*

Currently the script gave me no error, but the output was surprisingly all from the (else condition).

I couldnt make sure, since there are a lot of files inside it, but there should at least have some cases match the (if ) condition.

Can anyone have a look at the script i wrote and tell me if anything i have overlooked ?

Each file, I want to find if any three of the strings exists, if it does, I'll store its filepath in store_location.

Also the (i, j), was from an array with even number contents, odd number will be i; while even is j.
# !/usr/bin/perl use strict; use warnings; use File::Glob 'bsd_glob'; my $store_location = '/path/to/file'; my $Dir1 = "/somewhere"; my $Dir2 = "/somewhereelse"; my @first_directory = ( bsd_glob("$Dir1/"), bsd_glob("$Dir2/") ); my @store_array = qw (1 2 3 4 5 6); foreach my $first (@first_directory){ while(my ($i,$j) = splice(@store_array,0,2)){ my $second_directory = "$first/$i/$j"; if (-e $second_directory and -d $second_directory){ my @third_directory = bsd_glob("$first/$i/$j/*"); foreach my $file (@third_directory){ open(FILE, "<" , $file) or die "Can't open file '$file +': $!"; while (<FILE>){ if (($_ =~ /TbhODK/) or ($_ =~ /octuov/) or ($_ =~ + /qas_uop/)) { open(my $filehand, '>>', $store_location) or d +ie "Fail to open file '$store_location' $!"; print $filehand "$first/$i/$j/$file \n"; close $filehand; } } } close FILE; } else{ open(my $filehand, '>>', $store_location) or die "Fail to +open file '$store_location' $!"; print $filehand "$first/$i/$j (fail to exist)\n"; close $filehand; } } }#first_directory
Kindly let me know if it's unclear,I will improve the sentence.thank you perlmonks !