Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

perl : HTML:: Mason Print a perl hash inside HTML tags in a tabular format

by sravs448 (Acolyte)
on Sep 19, 2014 at 15:32 UTC ( [id://1101229]=perlquestion: print w/replies, xml ) Need Help??

sravs448 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to send a html email (report) about the values in a hash. But I couldnt print the hash values in a table format. I am using HTML::Mason to execute my perl commands (looping through a hash) and printing it in the end of report. But how can I execute my perl code to loop through hash inside html ?
use HTML::Entities; use Mail::Sendmail; use MIME::Lite; use Term::ANSIColor; use Time::localtime; use HTML::Mason; my $ti = localtime; my ($day,$month,$year)=($ti->mday,$ti->fullmonth,$ti->year); # DEFINE A HASH %coins = ( "Quarter" , 25, "Dime" , 10, "Nickel", 5 ); $html = <<END_HTML; <table border='1'> <th>Keys</th><th>Values</th> <%perl> while (($key, $value) = each(%coins)){ </%perl> <tr><td>$key</td>; <td>$value</td></tr>; <%perl> } </%perl> </table>; END_HTML $msg = MIME::Lite->new( from => 'abc@mydomain.com', To =>'def@mydomain.com', Subject =>'Report', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ <body> <html>$html</html> </body> }, ); $msg->attach( Type => 'image/gif', Id => 'banner.jpg', Path => 'C:\Users\Pictures\banner.jpg', ); MIME::Lite -> send ('smtp','xxxs.xxxx.xxxxx.com' ); $msg -> send;
  • Comment on perl : HTML:: Mason Print a perl hash inside HTML tags in a tabular format
  • Download Code

Replies are listed 'Best First'.
Re: perl : Print a perl hash inside HTML tags in a tabular format
by kennethk (Abbot) on Sep 19, 2014 at 17:17 UTC
    The problem is that you never actually hand your HTML to HTML::Mason to process - you are just attaching a string literal. While I've never tried to use Mason like this, Using Mason from a standalone script in HTML::Mason::Interp gives this example:
    my $outbuf; my $interp = new HTML::Mason::Interp (comp_root=>'<component root> +', data_dir=>'<data directory>', out_method=>\$outbuf); my $retval = $interp->exec('<component path>', <args>...); open(F,">mason.out"); print F $outbuf; close(F); print "return value of component was: $retval\n";
    so you'll want to include some similar processing on your $html variable.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: perl : Print a perl hash inside HTML tags in a tabular format
by zentara (Archbishop) on Sep 19, 2014 at 16:07 UTC
    But my perl code is not getting executed.

    What code is that? And what error messages do you recieve?


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      I am trying to print a hash values in tabular format (HTML)and send it in a email. But how can I execute my perl code to loop through hash inside html ?
Re: perl : Print a perl hash inside HTML tags in a tabular format
by choroba (Cardinal) on Sep 19, 2014 at 16:11 UTC
    Crossposted at StackOverflow. It is considered polite to inform about crossposting, so people not attending both sites don't waste their time hacking a problem already solved at the other end of the Internet wires.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      I will make sure to mention it next time. But I didnt get the solution yet. Please let me know if you can solve this issue? Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1101229]
Approved by hominid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found