Perl no longer holds an obvious upper hand on code length, especially considering that we can drop the Java example from eight lines to five with some whitespace manipulation.

I quite agree. As I was reading your deconstruction of the Perl/Java comparison, I thought about some code I wrote the other day.

I'm dealing with a big system at the moment, and in one place I have some database queries that return a dozen records or so of a thousand or more columns. I wanted to look at the result sets in Excel to trace a bug. So I extracted the query and recorded the results as a tab-delimited file. Load it into Excel.

Boom.

Turns out Excel has some really feeble limit on the number of columns a spreadsheet may contain. So I scratched my head for a moment, and thought... hmm, just have to transpose the rows and columns in the file, and I can load the transposed data in Excel and get on with the job.

I was going to paste the code here, but then I realised that it's sitting on a Windows server at work, so I'd have to log in through a VPN and dick around to get it out.

And then it occurred to me that if it took me about two minutes to write the code then, I could rewrite it again from memory. Here's the code, or something close to what I wrote. I typed this in, and compiled it, and it ran the very first time. I had to ponder the push statement for about 10 seconds, but that's it. And here it is:

use strict; use warnings; my @trans; while (<DATA>) { chomp; my @row = split /\t/; push @{$trans[$_]}, $row[$_] for 0..$#row; } print join( "\t", @$_ ), "\n" for @trans; __DATA__ A B C D E F G H 1 1 2 3 8 0 7 9 3 5 3 3 5 5 3 3

So there you have it. I imagine something like that is not going to come out at even 20 lines of Java, but if you want to take a stab at it, I'd be very interested at seeing even a rough sketch.

I'm not saying that my code is particularly clever or efficient, but it solved a specific problem in about as much time as it took me to write the code (although to be fair I did have a couple of off-by-one errors the first time around).

That's why I program in Perl.

• another intruder with the mooring in the heart of the Perl


In reply to Re^3: Interesting read: "Why I use perl and still hate dynamic language weenies too" by grinder
in thread Interesting read: "Why I use perl and still hate dynamic language weenies too" by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.