<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
        <head>
                <META http-equiv="Content-Type" content="text/html; charset=utf-8">
        </head>
        <body>
    <h1>Charlotte Perl Mongers</h1>
    <h2>2005 Template Challenge - TEMPLATE ENGINE</h2>
    <table>
      <tr>
        <th width="200" style="text-align:left;vertical-align:bottom;padding-left:10px">Name</th>
        <th width="50" style="vertical-align:bottom">Phone</th>
        <th width="100">Res/<br>Comm<span style="vertical-align:sup">*</span></th>
      </tr>
% my $cnt = 0; 
% foreach my $r(@{$data->{records}}) {
% $cnt++;
      <tr>
        <td><%= $r->{first} %>  <%= $r->{last} %></td>
        <td><%= $r->{phone} %></td>
        <td style="text-align:center"><%= $r->{res} ? 'RES' : 'COMM' %> </td>
      </tr>
% }
     
    </table>
    <p>Total Records = # <%= $cnt %></p>
    <hr style="margin-top:25px;width:100px" align="left">
    <p style="font-size:9pt"><span style="vertical-align:sup">*</span> Residential or Commerical listing</p>
  
</body>
</html>

<%init>
use strict;
use Data::Dumper;
$Data::Dumper::Purity = 1;

# Load data
my $data;
{
  local $/ = undef;
  my $input = <DATA>;
  $data = eval ( $input );
  die($@) if $@;
}

#$ENV{PATH} = "/bin:/usr/bin";
#my $template_file = $ARGV[0] || die "Usage: $0 <template>";

##
## YOUR CODE HERE
##

#__DATA__
$data = {
  ver => '1.0.0',
  records => [
    {
      first => 'Jane',
      last => 'Doe',
      phone => '800-222-3333',
      res => 1,
    },
    {
      first => 'John',
      last => 'Smith',
      phone => '704-123-4567',
      res => 1,
    },
    {
      first => 'Acme Electronics',
      last => '',
      phone => '704-123-4567',
      res => 0,
    },
  ],
};
</%init>

<%flags>
inherit => undef
</%flags>