Perhaps a little turnabout will illustrate my primary concern regarding the OP, i.e., the hyperbolic title:

<sarcasm>

Why Perl sucks (and some SQL to fix it)

I've been having problems with my Perl scripts for awhile, and now that I've read "SQL for Smarties", I realize the problem isn't my misunderstanding of Perl hashes, but that Perl is a bad language for data manipulation.

Consider the following two database tables:

+-------------+ +------------------+ | Products | | Supplier_Product | +-------------+ +------------------+ | PNO | PNAME | | SNO | PNO | +-----+-------+ +---------+--------+ | P1 | Screw | | S1 | P1 | | P1 | Screw | | S1 | P1 | | P1 | Screw | | S1 | P2 | | P2 | Screw | +------------------+ +-------------+
Now right off the bat, I'll say I need to maintain duplicate rows in order to compute some statistical rollups on the data, so the data model isn't flawed.

When I load these into my Perl hash, using PNO, and SNO as keys, I end up with just 2 Products rows, and 2 Supplier_Product rows! Perl is violating my requirements! Perl should read my mind, and automatically promote the hash values from scalars to arrayrefs for each duplicate key! Sure, I could write some code to check for and fix it, but the fact that Perl doesn't preserve my input is bad. Ergo, Perl sucks!

Fortunately, I can fix this by using SQL, which can preserve my multiset data model:

SELECT parts.pno FROM parts WHERE parts.pname = 'Screw' OR parts.pno IN (SELECT supplier_parts.pno FROM supplier_parts WHERE supplier_parts.sno = 'S1')
which returns the 3 P1s and 1 P2, which is consistent with my data model. And yet, I can also eliminate the duplicate rows by just adding a single keyword:

SELECT DISTINCT parts.pno FROM parts WHERE parts.pname = 'Screw' OR parts.pno IN (SELECT supplier_parts.pno FROM supplier_parts WHERE supplier_parts.sno = 'S1')
which returns 1 P1 and 1 P2. So SQL provides much greater flexibility than Perl. Ergo, Perl sucks.

And don't get me started about undef! How can anyone possibly use undef ? It doesn't mean anything, and Perl barks when I do something like

use warnings; my $foo = undef; print "This is some ", $foo, "\n";
Whats that all about ? Man, Perl sure does suck.

And why doesn't Perl automatically know what data I'm going to feed it at compile time ? I.e., why doesn't Perl complain at compile time when I enter:

perl somescript.pl 1 2 three four
for the script
my $sum; $sum += $_ foreach @ARGV; print $sum, "\n";
it prints the incorrect value 3! Sure, I could add some code to test the input and either translate it or throw it out if its not numeric, but that might effect performance. Man, Perl really sucks!

<sarcasm/>

Perl doesn't suck. Neither does SQL. They may be imperfect, they may not always do what we mean to do, but very few languages have ESP enabled runtime components. If you choose to use hyperbolic titles, and then use (by your own admission) flawed strawmen to illustrate your points, and further admit that the language you demean actually does accomodate your flawed exemplar (i.e., by using DISTINCT), your incendiary tone seems a bit misplaced.


In reply to Re: (OT) Why SQL Sucks (with a little Perl to fix it) by renodino
in thread (OT) Why SQL Sucks (with a little Perl to fix it) by Ovid

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.