Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by taint (Chaplain)
on Apr 26, 2013 at 19:46 UTC ( #1030887=note: print w/ replies, xml ) Need Help??


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

@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;


Comment on Re^2: File::Find seems grossly inefficient for performing simple file tasks
Re^3: File::Find seems grossly inefficient for performing simple file tasks
by Laurent_R (Parson) on Apr 26, 2013 at 21:53 UTC

    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;

        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.

Re^3: File::Find seems grossly inefficient for performing simple file tasks
by Anonymous Monk on Apr 27, 2013 at 10:52 UTC

    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

Re^3: File::Find seems grossly inefficient for performing simple file tasks
by DrHyde (Prior) on Apr 29, 2013 at 12:22 UTC
    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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-01 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls