Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Interesting read: "Why I use perl and still hate dynamic language weenies too"

by grinder (Bishop)
on Apr 17, 2007 at 20:13 UTC ( [id://610635]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Interesting read: "Why I use perl and still hate dynamic language weenies too"
in thread Interesting read: "Why I use perl and still hate dynamic language weenies too"

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

  • Comment on Re^3: Interesting read: "Why I use perl and still hate dynamic language weenies too"
  • Download Code

Replies are listed 'Best First'.
Re^4: Interesting read: "Why I use perl and still hate dynamic language weenies too"
by dewey (Pilgrim) on Apr 17, 2007 at 20:51 UTC
    I think I see what you mean. I'm going to look at Java stuff, but I really don't know exactly how I would go about it... probably load up the file and use a foreach or something along those lines. I'll take a crack at it sometime later (I have a lot of homework and I should really stop monking around!)

    ~dewey
Re^4: Interesting read: "Why I use perl and still hate dynamic language weenies too"
by Scott7477 (Chaplain) on Apr 19, 2007 at 17:25 UTC
    You probably haven't realized that likely thousands of Excel users have tried to figure out how to do this using VBA and spent hours beating their heads on the desk. I'm taking your code and putting it in the top of my code toolbox.++

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found