in reply to A question of efficiency

Good for you! Your colleague's version is unportable because it relies on Unix tools to be there, and depending on the system, creating processes (e.g. with system) can be expensive, CPU-wise / memory-wise. Your version is rather better, staying more within Perl, using the fact that Perl has already figured out how to perform certain operations to your advantage. Though it can still be cleaned up a bit (for instance you could use Getopt::Long to get the directory, and .* is generally ungood (you could use s/^hostname\s// and/or add a + after \s if you want to match one or more whitespace characters (but this is rambling and nested and should be stopped, and so (being the way it is) will be stopped now))), you are well on your way.

And, c, welcome to Perlmonks.

Replies are listed 'Best First'.
Re: Re: A question of efficiency
by Aighearach (Initiate) on Jul 18, 2001 at 18:53 UTC

    I just want to add my two cents and point out that the anti-.* attitude here theatens to install voodoo programming ideas in newcomers...

    .* is often non-optimal, but it is very bad system of choosing which way to do it if you are using dogmatic rules.

    Isn't the point of having many ways to do it the fact that the best way depends on context? Rather than encouraging bondage, I think it is healthier to encourage understanding of the cases where it causes problems.

    In this case you're right that it would be more efficient to replace it, but not because .* is bad... simply because it's more work than is needed. On the bright side, since the regex is anchored the .* is a very small performance hit, not the order of magnitude that is caused by truely awful uses of it.
    --
    Snazzy tagline here

      Note: None of what follows applies to the original poster who started this thread. This is merely my following up on a thought that Aighearach sparked.

      Aighearach wrote:

      I just want to add my two cents and point out that the anti-.* attitude here theatens to install voodoo programming ideas in newcomers...

      I have to confess that I'm rather ambivalent about this. I'm starting to get to the point where I don't even want to bother to point out good programming practices. Obviously, simply saying "don't use dot star" or "you must use strict" is not sufficient. premchai21 did provide a link to back up what was said, but I'm discovering more and more that people don't give a fig about how to program well.

      That raises an interesting question: do we just answer questions for people, or do we take the trouble to care about the quality of answers? Dominus, if I understood him correctly, seems to argue for the just answer the question camp (in a reply to a review that I wrote about Perl and CGI for the World Wide Web). Specifically, he wrote:

      I've heard plenty of arguments that you have to learn these style rules right from the beginning, apparently from people who think that if you once turn down the Path of Darkness your Soul is Lost Forevermore, and I think it's bullshit.

      I differ on this. Have you ever studied chess with an expert? Or the martial arts, tennis, or anything require great skill? One of the most common complaints from experts in various fields is that they are sick and tired of trying to get people to "unlearn" bad habits. Quite often, these people are a lost cause. Teach them right from the beginning and you don't have to fight that fight.

      That being said, so what? I, for one, am getting discouraged at giving answers and being told that I'm over the top (which I may very well be). I constantly see newbies telling more experienced people that they don't want to use strict. They don't need to use warnings. <sarcasm>They know exactly what they are doing but won't we please, please point out the one little bug in their program and then they'll ignore the other advice because they're clearly good enough to do without it anyway.</sarcasm>

      If you check out my posts, you'll notice that I haven't been posting as much lately. That's due, in large part, because of this issue. I'm still showing up and reading the threads because I want (need) to continue to improve my Perl. Plus, I have a lot of friends that I've met here that I want to keep in touch with, but I'm getting burnt out on helping people who don't want to be helped.

      I suppose I'm probably just in a funk right now and I'll snap out of it.

      Cheers,
      Ovid

      Vote for paco!

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

        Actually, I am an avid chess player and I never hear unlearning bad habits discussed. Actually a more common thing for the Masters to say is similiar to Perl's TMTOWTDI... it's something like, "the positional rules are generally good advice, but actually it's the exceptions that are most important."

        Personally, I think it's pretty much a law of nature. Not only the organisms with the highest populations survive, and survival techniques that would fail in most places, are ideal in others. I have a hard time seeing how this would fail to be true in all complex systems.
        --
        Snazzy tagline here