<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:
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.+-------------+ +------------------+ | Products | | Supplier_Product | +-------------+ +------------------+ | PNO | PNAME | | SNO | PNO | +-----+-------+ +---------+--------+ | P1 | Screw | | S1 | P1 | | P1 | Screw | | S1 | P1 | | P1 | Screw | | S1 | P2 | | P2 | Screw | +------------------+ +-------------+
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:
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 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.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')
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
Whats that all about ? Man, Perl sure does suck.use warnings; my $foo = undef; print "This is some ", $foo, "\n";
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:
for the scriptperl somescript.pl 1 2 three four
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!my $sum; $sum += $_ foreach @ARGV; print $sum, "\n";
<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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |