El módulo File::Path provee un medio conveniente para la creación y destrucción recursiva de directorios. File::Path El siguiente ejemplo usa la versión 2.04 del módulo:
pp2@nereida:~/src/perl/testing$ perl -MFile::Path -wde 0 Loading DB routines from perl5db.pl version 1.28 main::(-e:1): 0 DB<1> mkpath( '/tmp/chum/cham/', '/tmp/chum/chim', {verbose => 1} ) mkdir /tmp/chum mkdir /tmp/chum/cham/ mkdir /tmp/chum/chim DB<2> !! ls -ld /tmp/chum /tmp/chum/cham/ /tmp/chum/chim drwxr-xr-x 4 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum/cham/ drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:39 /tmp/chum/chim DB<3> rmtree('/tmp/chum/cham/', '/tmp/chum/chim', { verbose => 1, error => \$err_list }) rmdir /tmp/chum/cham rmdir /tmp/chum/chim DB<4> x $err_list 0 ARRAY(0x84b6178) empty array DB<5> !! ls -ld /tmp/chum /tmp/chum/cham/ /tmp/chum/chim ls: /tmp/chum/cham/: No existe el fichero o el directorio ls: /tmp/chum/chim: No existe el fichero o el directorio drwxr-xr-x 2 pp2 pp2 4096 2008-04-23 11:42 /tmp/chum (Command exited 2) DB<6> mkpath( '/tmp/chum/cham/', '/tmp/chum/chim', {verbose => 1} ) mkdir /tmp/chum/cham/ mkdir /tmp/chum/chim DB<7> !! touch /tmp/chum/cham/tutu.txt DB<8> !! touch /tmp/chum/chim/titi.txt DB<9> x rmtree('/tmp/chum/cham/', '/tmp/chum/chim', { verbose => 1, error => \$err_list }) unlink /tmp/chum/cham/tutu.txt rmdir /tmp/chum/cham unlink /tmp/chum/chim/titi.txt rmdir /tmp/chum/chim 0 4
Casiano Rodríguez León