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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759391296, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/modules/File/Find/determine_depth_level(65): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78