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

Hi Monks!
I have a sample code here to support my question which is about hiding the html that I will need later in my code to send it by email. I would like to hide the html portion of the code because I also need to run this code from the command line. Is there a way to hide the html part of a Perl code, hide it from view, but still process the html code as well and just show the command line format view of it? I hope I made myself clear.
Here is the code sample I mentioned :
#!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use CGI::Carp qw(fatalsToBrowser); use Date::Calc qw( Add_Delta_Days Decode_Date_US Today ); my $q = new CGI; my @todays; @todays = Today() unless ($ARGV[0] && (@todays = Decode_Date_US( $A +RGV[0] ))); my $page = "\n\n"; #my $page = "<br><br>"; # yesterday's date my @yesterday = Add_Delta_Days( @todays, -1 ); my $forms = " %-16s %-22s %-15s %-5s %s\n"; #my $forms = " %-16s %-22s %-15s %-5s %s<br>"; my $t_string = sprintf "%04d-%02d-%02d", @todays; my $y_string = sprintf "%04d-%02d-%02d", @yesterday; =code $page .= "<table width=\"100%\" border=\"0\" bgcolor=\"#ffffff\" cell +padding=\"0\" cellspacing=\"0\"> <tr> <td width=\"60%\">Date Format Sample:</td> <td width=\"40%\" align=\"left\"><b>$y_string</b></t +d> </tr> <tr> <td width=\"100%\" colspan=\"2\">&nbsp;</td> </tr> </table>"; =cut $page .= sprintf $forms, "TODAY", "YESTERDAY"; $page .= " ---------------------------------------------------------- +--------------\n"; $page .= " ----------$t_string - $y_string-----------\n"; print $page;
Thanks for looking!

Replies are listed 'Best First'.
Re: Report Format Help!
by wind (Priest) on Feb 04, 2011 at 21:07 UTC

    You're question is not clear to me at all I'm afraid. Some other monks may be able to understand better or know the right questions to ask, but maybe try to explain further?

    In the mean time, a simple stylistic suggestion is to use q and qq for single and double quoted strings respectively, especially when working with html that contains either.

    $page .= qq{<table width="100%" border="0" bgcolor="#ffffff" cellpaddi +ng="0" cellspacing="0"> <tr> <td width="60%">Date Format Sample:</td> <td width="40%" align="left"><b>$y_string</b></td> </tr> <tr> <td width="100%" colspan="2">&nbsp;</td> </tr> </table>};

    -Miller

      ...or even a HERDOC:

      my $page = "<div>hello world</div>\n"; my $x = 'goodbye'; $page .= <<"MORE_HTML"; <div>$x</div> MORE_HTML print $page; --output:-- <div>hello world</div> <div>goodbye</div>
Re: Report Format Help!
by Anonymous Monk on Feb 04, 2011 at 21:46 UTC

    Do you mean not show the html tags when displaying $page on the command line--i.e. just the text between the tags?

      ...if so, you can use the s/// operator:

      my $page = "<div>hello world</div>\n"; my $x = 'goodbye'; $page .= <<"MORE_HTML"; <div>$x</div> MORE_HTML print "$page\n"; $page =~ s/<.*?>//g; print $page; --output:-- <div>hello world</div> <div>goodbye</div> hello world goodbye

      That should be HEREDOC above--not HERDOC.

        The code in reference has two ways of showing this whatever information, one from the command line and another formating HTML code that will be emailed if you run the code from terminal/command line. But if you run this code from the command line the HTML code will shows and it will be html tags everywhere. And seeing the code for the command line will be difficult to cause of that. All I would like is to hide the HTML if I am running this code from the command line so the HTML code doesn't interfere with command line stuff.