in reply to file::find and ordered output

An option would be to munge your data before it gets passed to the produce_array() function with the preprocess option
find({ wanted => \&produce_array, preprocess => \&munge_data, }, $option{d});
See the File::Find manpage for more detail.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: file::find and ordered output
by Bjoern (Novice) on May 13, 2002 at 10:01 UTC
    I had a look at the manpage (it wasn't the first ;-) but couldn't quite understand how this (preprocess) would help me in my problem.

    quoting the man page of "file::find => preprocess"

    The value should be a code reference. This code reference is used to preprocess the current directory. The name of currently processed directory is in $File::Find::dir. Your preprocessing function is called after readdir() but before the loop that calls the wanted() function. It is called with a list of strings (actually file/directory names) and is expected to return a list of strings. The code can be used to sort the file/directory names alphabetically, numerically, or to filter out directory entries based on their name alone. When follow or follow_fast are in effect, preprocess is a no-op.

    "This code reference is used to preprocess the current directory."

    How can it affect the order of the directory processing?

    pondering

    Bjoern
      How can it affect the order of the directory processing?
      Its effect is that it changes what is passed to the wanted() coderef e.g
      find({ preprocess => sub { return sort { $b cmp $a } @_ }, wanted => \&process_array, }, @ARGV);
      This will sort the directory listing that process_array() gets in reverse alphabetic order. So basically the preprocess option allows you to change what the wanted() function receives from changing it's order to removing unwanted directory entries.
      HTH

      _________
      broquaint

      update: changed <=> to cmp in the sort() (thanks ariels)

        Thank you for the prompt input.

        The modification from "<=>" to "cmp" does it. It works fine now.

        Thanks again.

        Bjoern
        With your help I seem to get near the solution, but still it's weird...

        with $a <=> $b I get
        Anastacia Springsteen Laith al Deen

        with $b <=> $a I get
        Laith al Deen Springsteen Anastacia

        there seems to be a kind of sense in the output, but it's still not sorted correct....(or the alphabet in my brain is mixed up)

        I will work on it this evening an let you know about the solution (hope I find one), thanks for the input!

        still pondering

        Bjoern