<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6174882928438313624</id><updated>2011-04-21T22:08:01.983+02:00</updated><title type='text'>Nomology</title><subtitle type='html'>no·mol·o·gy &lt;i&gt;n.&lt;/i&gt;&lt;br&gt;The study and discovery of general physical and logical laws.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nomology.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nomology.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>jg</name><uri>http://www.blogger.com/profile/13520737717787874594</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='http://2.bp.blogspot.com/_DPSqDdDf5dM/SgqIosYzt6I/AAAAAAAAAC8/8qXMqwRqTRQ/S220/2807_74142537837_678592837_1655202_6262288_n.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6174882928438313624.post-2169660775876201068</id><published>2009-04-03T09:06:00.005+02:00</published><updated>2009-04-03T09:41:00.026+02:00</updated><title type='text'>Set intersection using hash slices</title><content type='html'>&lt;pre&gt;my @colours = qw/red green yellow orange white mauve blue ochre
                 pink purple gold silver grey brown steel/;
my @find = qw/red blue green black/;
my %colours;
@colours{@colours} = @colours;
my @found = grep { defined } @colours{@find};
print join( ', ', @found );
&lt;/pre&gt;
&lt;p&gt;This prints "red, blue, green". Adapted from a Perl.sig Perl Tip on &lt;a href="http://mailman.anu.edu.au/pipermail/perl.sig/2005-September/000014.html"&gt;slicing arrays and hashes&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6174882928438313624-2169660775876201068?l=nomology.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nomology.blogspot.com/feeds/2169660775876201068/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6174882928438313624&amp;postID=2169660775876201068' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/2169660775876201068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/2169660775876201068'/><link rel='alternate' type='text/html' href='http://nomology.blogspot.com/2009/04/my-colours-qwred-green-yellow-orange.html' title='Set intersection using hash slices'/><author><name>jg</name><uri>http://www.blogger.com/profile/13520737717787874594</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='http://2.bp.blogspot.com/_DPSqDdDf5dM/SgqIosYzt6I/AAAAAAAAAC8/8qXMqwRqTRQ/S220/2807_74142537837_678592837_1655202_6262288_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6174882928438313624.post-4687065370365943750</id><published>2008-09-29T10:13:00.001+02:00</published><updated>2008-09-29T10:19:18.836+02:00</updated><title type='text'>Lambdaish Perl</title><content type='html'>&lt;p&gt;Here's a snippet I wrote to test code references.&lt;/p&gt;
&lt;pre&gt;
my $f = sub {
  my $a = shift;
  &amp;$a();
};
&amp;$f( sub { print "hej\n"; } );
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6174882928438313624-4687065370365943750?l=nomology.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nomology.blogspot.com/feeds/4687065370365943750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6174882928438313624&amp;postID=4687065370365943750' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/4687065370365943750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/4687065370365943750'/><link rel='alternate' type='text/html' href='http://nomology.blogspot.com/2008/09/lambdaish-perl.html' title='Lambdaish Perl'/><author><name>jg</name><uri>http://www.blogger.com/profile/13520737717787874594</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='http://2.bp.blogspot.com/_DPSqDdDf5dM/SgqIosYzt6I/AAAAAAAAAC8/8qXMqwRqTRQ/S220/2807_74142537837_678592837_1655202_6262288_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6174882928438313624.post-5133790920010841422</id><published>2008-08-21T17:00:00.008+02:00</published><updated>2008-08-25T14:42:10.090+02:00</updated><title type='text'>Type cast in Perl DBI</title><content type='html'>&lt;p&gt;
&lt;b&gt;Problem:&lt;/b&gt; A seemingly innocuous SQL can turn out to be very strenuous for a database if it needs to do type conversion. Worst case scenario is a full table scan just because the WHERE clause contains mismatching types in a comparison. Imagine, for example, that the column &lt;code&gt;id&lt;/code&gt; in the table &lt;code&gt;customers&lt;/code&gt; below is a VARCHAR. If we're talking to an Oracle database and send it an integer, the resulting execution plan could be near disastrous.
&lt;/p&gt;
&lt;pre&gt;
SELECT *
FROM customers
WHERE id = ?
&lt;/pre&gt;
&lt;p&gt;
In Perl, an untyped language where strings and integers are interchangeable, how can I ensure that I'm sending a string via DBI to the database if the string only contains numerals?
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Solution #1:&lt;/b&gt; Wrap the value in a string:
&lt;/p&gt;
&lt;pre&gt;
$sth-&gt;execute( "$indata" );
&lt;/pre&gt;
&lt;p&gt;
Perl is more of a "semi-typed" language than a totally untyped language, and keeps track of whether a scalar is a string or an integer. The only reason the values are interchangeable is because of the transparent type conversion.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Solution #2:&lt;/b&gt; Use the explicit &lt;code&gt;bind_param&lt;/code&gt; method and specify the data type:
&lt;/p&gt;
&lt;pre&gt;
use DBI qw(:sql_types);
[...]
$sth-&gt;bind_param( 1, $indata, SQL_VARCHAR );        # index, value and type
$sth-&gt;execute();
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6174882928438313624-5133790920010841422?l=nomology.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nomology.blogspot.com/feeds/5133790920010841422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6174882928438313624&amp;postID=5133790920010841422' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/5133790920010841422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/5133790920010841422'/><link rel='alternate' type='text/html' href='http://nomology.blogspot.com/2008/08/type-cast-in-perl-dbi.html' title='Type cast in Perl DBI'/><author><name>jg</name><uri>http://www.blogger.com/profile/13520737717787874594</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='http://2.bp.blogspot.com/_DPSqDdDf5dM/SgqIosYzt6I/AAAAAAAAAC8/8qXMqwRqTRQ/S220/2807_74142537837_678592837_1655202_6262288_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6174882928438313624.post-2200164944955300296</id><published>2008-08-04T15:06:00.002+02:00</published><updated>2008-08-27T09:13:55.974+02:00</updated><title type='text'>Not to be confused with nomología</title><content type='html'>&lt;p&gt;This blog is my personal programming blog. It's not about the study of law or jurisprudence. As evidenced by the subtitle, I am using the second meaning of the word "nomology". I want a space where I can talk specifically about source code and programming languages, so I'll only be talking about the physical and logical laws as evident in and applied to computer programming.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6174882928438313624-2200164944955300296?l=nomology.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nomology.blogspot.com/feeds/2200164944955300296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6174882928438313624&amp;postID=2200164944955300296' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/2200164944955300296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6174882928438313624/posts/default/2200164944955300296'/><link rel='alternate' type='text/html' href='http://nomology.blogspot.com/2008/08/not-to-be-confused-with-nomologa.html' title='Not to be confused with nomología'/><author><name>jg</name><uri>http://www.blogger.com/profile/13520737717787874594</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='http://2.bp.blogspot.com/_DPSqDdDf5dM/SgqIosYzt6I/AAAAAAAAAC8/8qXMqwRqTRQ/S220/2807_74142537837_678592837_1655202_6262288_n.jpg'/></author><thr:total>0</thr:total></entry></feed>
