Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: File::Find seems grossly inefficient for performing simple file tasks

by Laurent_R (Abbot)
on Apr 26, 2013 at 21:53 UTC ( #1030899=note: print w/replies, xml ) Need Help??

in reply to Re^2: File::Find seems grossly inefficient for performing simple file tasks
in thread File::Find seems grossly inefficient for performing simple file tasks

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 file and then say that:

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

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).

Replies are listed 'Best First'.
Re^4: File::Find seems grossly inefficient for performing simple file tasks
by taint (Chaplain) on Apr 26, 2013 at 22:14 UTC
    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.


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

      Hi Chris,

      I guess that I probably was not clear enough to explain what I meant. I know what the find command is doing and I know that it has very little (if anything) to do with grep. My point was something else.

      I just meant to give another completely different example to show that it does not make too much sense to compare the programming efficiency (in terms, for example, of the quantity of code needed for a specific task) of a shell or built-in Unix command and the coding of the same actions in a Perl program. Because to make the comparison fair, you would need to know the quantity of code that is used behind the scene (e.g. the source code of the find command) when you run a find command. I used a very simple grep example just to make the case more obvious.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030899]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-05-28 20:02 GMT
Find Nodes?
    Voting Booth?