in reply to File slurping efficiency

Thanks for the tips, guys... this Perl efficiency stuff where it's at. I have a related question now... If I went with method B, and ran the ultra-long string through a pattern match, would it be to my advantage to study() the string first, or will the string's length make it take too blasted long? I have never actually used the study() function before, so I don't know much about its impact.

If nobody replies to this, I'll take that to mean "get off your lazy butt, get a benchmark utility, and test it yourself, bozo!" That's perfectly reasonable, and very true, but I'll probably think the "bozo" was out of line.

Alan "Hot Pastrami" Bellows
-Sitting calmly with scissors-

Replies are listed 'Best First'.
(Ovid) RE(2): File slurping efficiency
by Ovid (Cardinal) on Aug 12, 2000 at 02:15 UTC
    First, I want to say that I laughed my head off when I read your sig line (have you seen Running With Scissors?).

    You need to be very careful with study. To the best of my knowledge, it's always been very buggy. In fact, in later versions of Perl (not sure about 5.6), successful matches against $_ can fail if you're using study, even if the string your matching against isn't what you studied. Apparently, the only way to get around this is to explicitly undef the studied string as soon as you are done with it (see Mastering Regular Expressions, second edition, page 289).

    If you're willing to risk the problems with study, you should go ahead and benchmark it, but I wouldn't bother with it, personally.

    Cheers,
    Ovid

Study()'s use
by gryng (Hermit) on Aug 12, 2000 at 02:40 UTC
    Hi Hot Pastrami,

    study() (correct me if I'm wrong here guys) is only useful if you are going to search many keywords on the same string. Think of it as building an index of where all the a's and the b's, etc.. are located in the string so that if you need to see if 'airplane' is there, you can look really quickly (ok, so it doesn't do exactly that... but it's the same idea! :) ).

    So if you are only going to look at a few keywords then don't bother with study, but if you are going to look at a few hundred keywords, then it might help alot more! (The exact cut off value depends on the length of the string, the length of the keywords, and the number of the keywords -- yes the length of the keywords effects the speed of a lookup, both ways).

    Cheers,
    Gryn

RE: Re: File slurping efficiency
by ZZamboni (Curate) on Aug 12, 2000 at 02:48 UTC
    You maybe know this already, but in case you don't: if you want to do some benchmarking, make sure you check out the Benchmark module, which is part of the Perl standard distribution.

    --ZZamboni