5 ms·
Unfortunately that Perl code is not a good representative of how one should write Perl in 2011.
by szabgab 15y ago
Unfortunately that Perl code is not a good representative of how one should write Perl in 2011.
- gglanzani 15y agoDo you care rewriting it for us(me)? Just curious for how perl should look like now
- peteretep 15y agoI'm a complete cowboy, and would probably write something like: http://pastebin.com/mvjTG9XG http://pastebin.com/mvjTG9XG Edit: spot where I missed a comma :-P
- eCa 15y agoI don't have time for that.. Looks good though, much more readable.
- autarch 15y agoDon'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} );
- peteretep 15y agoSure. 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?
- rjbond3rd 15y agoIt 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');
- pyre 15y ago> knee-jerk reaction Fixed that for you.
- pyre 15y agoMade the SQL portion a little more readable: http://pastebin.com/MNzD0NSE http://pastebin.com/MNzD0NSE
- rjbond3rd 15y agoAh, much better. [It doesn't need saying but one could be even lazier and instead of generating a timestamp, one could use NOW() or an automatic timestamp field.]