Re:Your own movie database in 5 minutes with IMDb API and Perl
by szabgab on Monday November 21, 2011 @01:29PM
(#3262176)
Unfortunately that Perl code is not a good representative of how one should write Perl in 2011.
[ Parent
| on HN ]
Re:Your own movie database in 5 minutes with IMDb API and Perl
by gglanzani on Monday November 21, 2011 @03:14PM
(#3262615)
Do you care rewriting it for us(me)? Just curious for how perl should look like now
Re:Your own movie database in 5 minutes with IMDb API and Perl
by peteretep on Monday November 21, 2011 @03:44PM
(#3262740)
I'm a complete cowboy, and would probably write something like: http://pastebin.com/mvjTG9XG
Edit: spot where I missed a comma :-P
Re:Your own movie database in 5 minutes with IMDb API and Perl
by autarch on Monday November 21, 2011 @04:39PM
(#3262927)
Don't quote the variables, use placeholders. It's much simpler, and it's safer.
$dbh->do( 'INSERT INTO movie_collection VALUES ( ?, ?, ... )', undef, @{ $data->{movie} }{@fields} );
Re:Your own movie database in 5 minutes with IMDb API and Perl
by peteretep on Monday November 21, 2011 @04:50PM
(#3262962)
Sure. Where's the dbh coming from in this example though? And how do I get it out again nicely to print the SQL to the command line?
Re:Your own movie database in 5 minutes with IMDb API and Perl
by rjbond3rd on Monday November 21, 2011 @05:31PM
(#3263122)
It doesn't exist in the example, which is only creating the INSERT statements, presumably to pipe into, e.g., the mysql command line client:
mysql -u user -p < inserts.sql
If the $dbh were in the example, then:
(a) you could avoid that (eek!) archaic escapeSingleQuote() sub, e.g., my $released = $dbh->quote($released), but much better:
(b) as mentioned, use the SQL placeholders to avoid quoting altogether, but
(c) if you really want to print the INSERT's, just do method (a). Start by declaring the $dbh, e.g. for MySQL:
my $dbh = DBI->new( 'DBI:mysql:my_db', 'db_user', 'db_pass');
Re:Your own movie database in 5 minutes with IMDb API and Perl
by pyre on Monday November 21, 2011 @05:17PM
(#3263053)
> knee-jerk reaction
Fixed that for you.
Re:Your own movie database in 5 minutes with IMDb API and Perl
by pyre on Monday November 21, 2011 @05:16PM
(#3263049)
Made the SQL portion a little more readable: http://pastebin.com/MNzD0NSE