Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • As soon as I saw that ~100 line Java program, I immediately wrote a one-line Perl equivalent:

    while () { print unless /^(192\.(9|18|29)\.|\.(?i:(gif|jpg|css)) HTTP)/; }

    Of course, you could match his argument conventions precisely, but why bother? This form is the normal Perl way to do it, and the author's Perl and Java arguments were already different.

    I haven't benchmarked this one-liner, but I bet it's faster than the author's Perl version, and likely faster than the Java code as well. It might be a
    --

    Deven

    "Simple things should be simple, and complex things should be possible." - Alan Kay

    • You may want to double check the position of your ^

      As someone said somewhere (petdance iirc), when making optimized solutions, test. It's something a lot of people seem to not be doing in this thread (either here or in davorg's journal). If you're going to make it more efficient, you might as well make it produce the same results.

      At work, I produced a shiny new version of a previous routine. I couldn't really benchmark them though: the previous version processed much less data due to a bug in its impleme
      --
        ---ict / Spoon
      • Actually, I wrote it with the ^ inside the parens originally when I copied it onto here, I dropped the outer parens because they were really redundant. Then I decided to put them back in for readability and mention that they could be dropped instead.

        Unfortunately, when I put them back in, I put the opening paren after the ^ (force of habit) when that's not what I meant. My bad!

        I also lost the <> operator inside the while (), while we're being pedantic. :-) (I'm pretty sure this was eaten by the Slashcode software.)

        To be really pedantic, I should point out that the case-insensitive part matches other capitalizations like "Css" that the original code didn't -- to be completely identical, I should have kept it case-sensitive and listed just the particular variations used in the original code, but I thought case-insensitive was more true to the intent of the original...

        The only reason I didn't test it was because I didn't have any available data to run it on, and I didn't feel like constructing some sample test data. I left it as "an exercise for the reader". :-)

        But hey, you knew what I meant! The point was that in a minute or two, you can make a one-liner in Perl that does the same as the Java 100-liner, and probably quite a bit faster, too.
        --

        Deven

        "Simple things should be simple, and complex things should be possible." - Alan Kay