Finding directories from a list (case-insensitive)

1st off, I started looking into using Perl just a few days ago.  So I'm quite the noob at all of this.  My boss really wants me to use Perl,  so here I am.

I need to check to see if certain sub directories exist by comparing them to a list of possible names.

Users might change the case or abbreviate certain parts of the directory from the standard name.
So dir_one might end up being named Dir_one, dir_ONE, DIR_ONE or even dir_1....
( I can handle the dir_1 case as an exception later in the code it that helps)

My results should be a list of valid directories as well as having a list of missing directories.
 
I've currently borrowed some code from Colin that checks two arrays and returns duplicates and differences:

% perl -Mstrict -Mwarnings
sub find_dups($$){
  my %hash1 = map { $_=>1 } @{+shift};
  return grep { $hash1{$_} }  @{+shift};
}

print join(', ', find_dups([qw(a c d e f g h)], [qw(g f b e)])), "\n";

Gives => g, f, e

And this one that finds differences:

sub find_uniques($$){
  my %hash1 = map { $_=>1 } @{+shift};
  my %hash2 = map { $_=>1 } @{+shift};
  my @notin2 = grep { !delete($hash1{$_}) } keys(%hash2);
  return @notin2, keys(%hash1);
}
print join(', ', find_uniques([qw(a c d e f g h)], [qw(g f b e e e e)])), "\n";
    Which returns b, h, a, c, d as expected.

I need to have something that ignore case in the compare but save the valid names at the end.

Thanks
Randy



ISGDudeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
ozoCommented:
sub find_dups($$){
  my %hash1 = map { (lc) =>1 } @{+shift};
  return grep { $hash1{+lc} }  @{+shift};
}
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
ISGDudeAuthor Commented:
OK that works.. which leads me to more noob issues

print join(', ', find_dups([qw(a c d e f g h)], [qw(G F d e)])), "\n";
prints out "d G F"  

But,
@list1 = qw(a c d e f g h);
@list2 = qw(G F d e) ;
print join(', ', find_dups(   @list1, @list2   ), "\n";
returns nothing...????

Also, I'd like to capture the results into an array or string.  
I seem to be having trouble there too.

(These are the last add-on questions, I promise)
R.


0
 
ozoCommented:
print join(', ', find_dups(  \@list1,\ @list2   ), "\n";
or
print join(', ', find_dups(  [@list1], [@list2]   ), "\n";
0
 
ozoCommented:
$result = join(', ', find_dups([qw(a c d e f g h)], [qw(G F d e)]));
print $result,"\n";
0
 
ozoCommented:
see
perldoc -q intersection
perldoc -q duplicate
perldoc perldata
perldoc perlsub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.