Guest
Public paste!

root

By: a guest | Jun 30th, 2009 | Syntax: None | Size: 0.49 KB | Hits: 7 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/perl
  2. use strict;
  3. use DBI;
  4.  
  5. sub db_connect {
  6.         my $dsn = "delfi;host=localhost;mysql_enable_utf8=1";;
  7.         my $dbh = DBI->connect("dbi:mysql:$dsn", "mysql", "", { PrintError => 0, RaiseError => 1 });
  8.  
  9.         return $dbh;
  10. }
  11.  
  12. my $dbh = db_connect();
  13. my $sth = $dbh->prepare("SELECT name FROM newsCategories WHERE ID=?");
  14. $sth->execute(2);
  15. my ($rootname) = $sth->fetchrow or die 'Non existing root category';
  16. print "rex: ", $1, "\n" if $rootname =~ /^(...)/;
  17. print "substr: ", substr($rootname, 0, 3) . '...';