#array
@myfiles = ("public", "A0", "B0", "KS");
Now, I just want A0, B0 and dont want any other elements like public and KS. So, for that I have below code:
my @MYFILES;
foreach $names ( @myfiles ) {
next if ( $names =~ m/public/);
next if ( $names =~ m/KS/ ) ;
push (@MYFILES, "$names");
}
Now, next if statements helps to skip the elements that I dont want in my new array "@MYFILES"
But, instead of next if statements, if I want to create a list of not required elements like public, KS and just call that in foreach loop which takes care and only gathers required elements like A0, B0 then how can it be done? I mean :
Something like creating hash %bad_dir = ( public = 1, KS = 1 ); and then calling that in foreach loop like below:
%bad_dir = ( public = 1, KS = 1 );
foreach $names ( @myfiles ) {
next if ( exists ( $bad_dirs{$names} ));
#but this code does not work ( Reason for creating hash is I will be having many such files that I don't need and I want to use next if statements. I want some shorter way. )
}
How can I do that.
thanks,