topical media & game development

talk show tell print

mashup-gmaps-ch09-08.pl / pl



  #!/usr/bin/perl
  
  use DBI;
  use strict;
  
  my dbh = DBI->connect( 'dbi:mysql:database=mapsbookex;host=db.maps.mcslp.com',
                          'mapsbookex',
                          'examples',
                          );
  
  if (!defined(dbh))
  {
      die "Couldn't open connection to database\n";
  }
  
  my @lines;
  
  my sth = dbh->prepare('select title,lat,lng from ch08_simple');
  sth->execute();
  
  while (my row = sth->fetchrow_hashref())
  {
      push(@lines,
           sprintf('<marker lat="\%f" lng="\%f" title="\%s"/>',
                   row->{lat},
                   row->{lng},
                   row->{title}));
  
  }
  sth->finish();
  
  if (scalar @lines > 0)
  {
      print("<markers>\n",
            join("\n",@lines),
            "</markers>\n");
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.