Search notes:

Perl module File::Find - determine depth level with preprocess and postprocess

Before File::Find enters a directory, it calls the (optional) preprocess, before it is leaving a directory it calles the (optional) postprocess hook functions.
The following script uses these hook functions to increment or decrement $level.
Finally, wanted prints the filename ($_) indented by twice the amount of $level.
#!/usr/bin/perl
use warnings;
use strict;

use File::Find;

my $level = 0;

find(
  {
     preprocess  => sub {$level ++; @_},
     postprocess => sub {$level --; @_},
     wanted      => sub {print '  ' x $level, $_, "\n"}
  },
  '..'
 );
Github repository PerlModules, path: /File/Find/determine_depth_level.pl

See also

File::Find
Perl modules

Index