http://www.perlmonks.org?node_id=1030862


in reply to File::Find seems grossly inefficient for performing simple file tasks

There where a couple of blog posts on the speed of the many CPAN modules avalable for file finding.

There looks to be quite a selection avalable. File::Find looks to be fastest. There are alternatives with different APIs for the programmer that you may find easer to use, but some are rather slow.

The author looks be same person as rjbs here, but that is not certain as there are no links from one account to the other.

  • Comment on Re: File::Find seems grossly inefficient for performing simple file tasks

Replies are listed 'Best First'.
Re^2: File::Find seems grossly inefficient for performing simple file tasks
by taint (Chaplain) on Apr 26, 2013 at 19:46 UTC
    @DrHyde, @BrowserUk, @chrestomanci.
    Greetings to all of you, and thank you for your replies!
    While I can completely understand the conclusion all of you arrived at;
    Please let me take the time to clarify "grossly inefficient", as to my intended assessment.
    I was referring to the volume of code (source) that find2perl emitted as an alternative to the shell' find && rm script.
    So to be clear; I do/have not found Perls' File::Find to be "grossly inefficient", but rather; it appeared (to me) that the code/source required to achieve the same results in Perls' File::Find, was much greater than tha shells' counterpart.
    I definitely meant no disrespect to Perl || Perls' File::Find. :)

    @chrestomanci
    The links you provided made for some interesting reading -- thanks!

    Best wishes.

    --chris

    #!/usr/bin/perl -Tw
    use perl::always;
    my $perl_version = "5.12.4";
    print $perl_version;

      Hmmm, that type of comparison does not really make sense to me.

      If I want to find all the lines that contains the letters "ab" in a file, using shell script, I can just write:

      grep ab file.txt

      If I want to do that in a Perl one-liner, there is just no way I can do that in just 8 characters plus the name of the file. Just the "perl -e " sequence has 8 characters, and I haven't even started to give the code of my Perl script. The script could be as short as something like this:

      perl -ne 'print if /ab/' file.txt

      (Maybe someone will find some way of doing it shorter, but that's not the point.)

      There is just no way a Perl program could be as simple (as concise, as short) as a simple shell command, but it makes no sense to compare them. A shell command may contain hundreds or thousands of code source lines. If you go this way, I could also include all the code that I want or need in an x.pl file and then say that:

      grep ab file.txt can be replaced by the following: x.pl

      which shows that Perl is far more concise than the shell or almost pretty anything else.

      I should add that I don't know many languages where something like this:

      perl -ne 'print if /ab/' file.txt

      can be coded so concisely (or course, sed and awk could do that, but we are again comparing things that are not really comparable).

        Greetings Laurent_R,
        The "find" in this case, has nothing to do with finding something within a file. But rather, is an attempt to find files themselves. :)
        It is a search, that attempts to find all files within a certain range; in this case, over a certain age. Hence, all the chatter about ctime, atime, etc...
        Hope this clears things up, a bit. :)

        Best wishes.

        --chris

        #!/usr/bin/perl -Tw
        use perl::always;
        my $perl_version = "5.12.4";
        print $perl_version;
      Sure, it takes more code. That's what happens when you try to use a general purpose language instead of a task-specific mini-language.
        Greetings all,
        In the end, I ended up simply using a "system" call within Perl:
        #!/usr/bin/perl -w use strict; use POSIX qw(strftime); $|++; my $gmtstring = strftime "%F %H:%I:%S", localtime; my $filename = "symlinked-iso-file-with-limited-lifetime"; my $arg1 = ('-XP . -type l -cmin'); my $arg2 = ('+15'); my $arg3 = ('xargs rm'); system("/usr/bin/find $arg1 $arg2 | $arg3");
        It's just going to have to do, until I become more proficient in Perl.

        Thank you all again, for all your time, consideration, and patience. :)

        --chris

        #!/usr/bin/perl -Tw
        use perl::always;
        my $perl_version = "5.12.4";
        print $perl_version;

      So to be clear; I do/have not found Perls' File::Find to be "grossly inefficient", but rather; it appeared (to me) that the code/source required to achieve the same results in Perls' File::Find, was much greater than tha shells' counterpart.

      Yes, we understand, you run screaming at sunset because you think the sky is burning