Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

rmtree(["/home/perls/public_html/sector"], 1, 1);
When it removes all files of the directory it shows messages for each file. How can you store these messages in such a way you can print them however you want such as font color and line breaks? As it is, it prints everything in one block in red text. I want line breaks and black text.

Replies are listed 'Best First'.
Re: Custom File::Path messages
by NetWallah (Canon) on Oct 23, 2004 at 03:41 UTC
    Use File::Find instead. Sample below (Not the most elegant code - this is just an illustration on how it can be used).
    use File::Find; my $ig=0; find( {wanted=>\&del, bydepth=>1, postprocess=>\&dirp}, 'E:\Documents and Settings\vijay\test'); ###### sub del{ # $ig is set to 1 if this is a DIRECTORY $ig==1 and return $ig=0; # Reset it ## Use the $ig toggle to do a REMDIR, before returning print qq($_ \n); ## Remove (Unlink) the $_ file here .... } #### sub dirp{ # Called for DIRECTORIES only print qq(***DIR:$File::Find::dir\n); $ig=1; }

        Earth first! (We'll rob the other planets later)

Re: Custom File::Path messages
by grinder (Bishop) on Oct 23, 2004 at 11:53 UTC

    You might want to look at this recent question: Challenge: Capturing stdout from a function call. which asks for something similar.

    That said, File::Path is ancient code, and should be one the first modules to be taken out and shot when the revolution (Perl6) comes. Magic-number positional parameters are just so... twentieth century.

    I don't mind modules I have to look up in order to remind myself how to use them, but when I have to look a module definition up in order to understand code already written there's something wrong.

    Not to mention the fact that a library module that calls print is just wrong, wrong, wrong.

    If File::Path were written today, it would use a hash, which would offer you named parameters and thus the code that uses it would be self-documenting. This would avoid the dilemma of what you are supposed to do when you want to set the third positional parameter when you don't care about the second. In this case you have to make a choice about what to set the second to, in order to get at the third.

    File::Finder and File::Find::Rule are two other modules with nice interfaces that will let you do what you want.

    - another intruder with the mooring of the heat of the Perl