Search code examples
perlperl-data-structures

what is ($file eq '.' || $file eq '..') ?


I found this script that read from directories recursively and i have troubles understanding this line of code :

if ($file eq '.' || $file eq '..')

so if someone could explain this a little bit , and thanks .


Solution

  • It tests if file is equal to '.' (current directory) or '..' parent directory. This sort of thing is used when you are searching the directory tree but do not want to process these special files.

    Example:

    For each file in SomeDirectory:
      if file is current directory, '.', or parent directory ,'..'
        skip
      do something with file
    EndFor