#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    63
    Rep Power
    7

    How to display values in perl html table?


    Hi,

    I've the below HTML code inside a perl file where i'm sending a mail. The mail part and html part is fine. but when i try to add perl code inside DATA as $BStatus and $AStatus its showing as it is! Values for the above two variables is already present and i confirmed it.
    How do i display its values. Kindly help.

    Code:
     $tme=localtime(); $subject='Android Results';  use MIME::Lite; my $msg = MIME::Lite->new ( Subject => $subject, From    => 'xyz@gmail.com', To      => 'xyz@gmail.com', Type    => 'text/html', Data    => '<H1>Summary</H1><br> <table border="1"> <tr bgcolor="#87CEFA"> <th>Platforms</th> <th>BStatus</th> <th>AStatus</th> <th>Results</th> </tr>  <tr> <th bgcolor="#87CEFA">123</th> <td>$kstatus</td> <td>$astatus</td> <td> <a href="http://xx.xxx.xx.xx/Android/123.html">123-Results</a> </tr>  <tr> <th bgcolor="#87CEFA">atgs</th> <td>row 2, cell 2</td> <td>row 2, cell 3</td> </tr>  <tr> <th bgcolor="#87CEFA">8765</th> <td>row 2, cell 2</td> <td>row 2, cell 3</td> </tr>  <tr></table>
    '
    );
    $msg->send();
    Thanks.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    Single-quoted strings can not contain variables. They are considered literals.

    You need to double-quote, or use another construct such as a HERE doc to allow interpolation.

    Code:
    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    use MIME::Lite;
    
    my $subject='Android Results';
    my $kstatus = 'k is good';
    my $astatus = 'a is doing fine';
    
    my $data = <<HERE;
    <h1>Summary</h1><br>
      <table border="1">
        <tr bgcolor="#87CEFA">
          <th>Platforms</th>
          <th>BStatus</th>
          <th>AStatus</th>
          <th>Results</th>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">123</th>
          <td>$kstatus</td>
          <td>$astatus</td>
          <td><a href="http://xx.xxx.xx.xx/Android/123.html">123-Results</a></td>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">atgs</th>
          <td>row 2, cell 2</td>
          <td>row 2, cell 3</td>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">8765</th>
          <td>row 2, cell 2</td>
          <td>row 2, cell 3</td>
        </tr>
      </table>
    HERE
    
    print $data;
    
    my $msg = MIME::Lite->new (
    	Subject => $subject,
    	From    => 'xyz@gmail.com',
    	To      => 'someone@fanboy.com',
    	Type    => 'text/html',
    	Data    => $data
    );
    
    MIME::Lite->send;
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    63
    Rep Power
    7
    Thanks very much. It worked. Is there any way i can add if else loop inside the html contents?

    Thanks.
  6. #4

  7. Join Date
    Jul 2013
    Location
    Melbourne
    Posts
    43
    Rep Power
    0
    Originally Posted by keath
    Single-quoted strings can not contain variables. They are considered literals.

    You need to double-quote, or use another construct such as a HERE doc to allow interpolation.

    Code:
    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    use MIME::Lite;
    
    my $subject='Android Results';
    my $kstatus = 'k is good';
    my $astatus = 'a is doing fine';
    
    my $data = <<HERE;
    <h1>Summary</h1><br>
      <table border="1">
        <tr bgcolor="#87CEFA">
          <th>Platforms</th>
          <th>BStatus</th>
          <th>AStatus</th>
          <th>Results</th>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">123</th>
          <td>$kstatus</td>
          <td>$astatus</td>
          <td><a href="http://xx.xxx.xx.xx/Android/123.html">123-Results</a></td>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">atgs</th>
          <td>row 2, cell 2</td>
          <td>row 2, cell 3</td>
        </tr>
        <tr>
          <th bgcolor="#87CEFA">8765</th>
          <td>row 2, cell 2</td>
          <td>row 2, cell 3</td>
        </tr>
      </table>
    HERE
    
    print $data;
    
    my $msg = MIME::Lite->new (
    	Subject => $subject,
    	From    => 'xyz@gmail.com',
    	To      => 'someone@fanboy.com',
    	Type    => 'text/html',
    	Data    => $data
    );
    
    MIME::Lite->send;
    Thanks I got the same error thanks for solution.
  8. #5
  9. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    Originally Posted by ramki067
    Is there any way i can add if else loop inside the html contents?
    Yes. You can build a string up piece by piece, and combine them later using concantenation.

    But I would be more inclined to use a template, which would allow you to keep all the HTML out of your code and make it easier to maintain.

    HTML::Template

    It allows loops.

IMN logo majestic logo threadwatch logo seochat tools logo