[Gllug] Perl scripting challenge

salsaman at xs4all.nl salsaman at xs4all.nl
Wed Oct 4 15:39:58 UTC 2006


> Hello,
>
> A quick plea/challenge to those of you who are Perl minded.
>
> I need a script that searches a file system looking for files that are
> named like so:
>
> foo.txt
> Foo.txt
> FOO.txt
> foO.tXt
>
> and so on in the same directory. Apparently someone thought that this
> would be a good idea to do!
>
> The script just needs to report the duplicated instances rather than
> actually do anything to the file and I'd like to be able to call it like
> this:
>
> ./magic_script.pl /home
>
> to run the script against the contents of the /home directory.
>
> Thanks
>
> ~sm
>
> --
> Gllug mailing list  -  Gllug at gllug.org.uk
> http://lists.gllug.org.uk/mailman/listinfo/gllug
>

Try this (untested !):

#!/usr/bin/perl

          opendir DIR,"$ARGV[0]";
 	  my @allfiles=readdir(DIR);
          closedir DIR;

          foreach my $file (@allfiles) {
 	   if (-f "$ARGV[0]/$file") {
            my $file_lower=toLOWER_uni($file);
            if (defined $hash{$file_lower}) {
             unless ($hash{$file_lower} eq "") {
              print $hash{$file_lower}."\n";
              $hash{$file_lower}="";
             }
             print $file."\n";
            }
            else {
             $hash{$file_lower}=$file;
            }
           }
          }


Gabriel.
http://lives.sourceforge.net


-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list