Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

use HTML; # !!!

by japhy (Canon)
on Jul 26, 2002 at 17:26 UTC ( #185604=snippet: print w/replies, xml ) Need Help??
Description: Embed HTML directly into your Perl code. Just be sure you're using warnings.
package HTML;

$SIG{__WARN__} = sub {
  if ($_[0] =~ /readline\(\) on unopened filehandle (\S+)/) {
    print "<$1>";
  elsif ($_[0] !~ /only once/) { warn @_ }

sub import {
  my $pkg = caller;
  *{ $pkg . "::glob" } = \&tag;

sub tag {
  my $tag = shift;
  $tag =~ s/\s+$//;
  wantarray ? "<$tag>" : print "<$tag>";


#!/usr/bin/perl -w
use HTML;

    <title>, "This is vile", </title>,
  <body bgcolor="#ffffaa">,
  <tt>, "japhy", </tt>, " is insane.",
Replies are listed 'Best First'.
Re: use HTML; # !!!
by dragonchild (Archbishop) on Jul 26, 2002 at 18:51 UTC
    Mod needed for 5.005_3:
    if ($_[0] =~ /readline\(\) on unopened filehandle (\S+)/ || $_[0] =~ /Read on (?:unopened|closed) filehandle <(\S+)>/ ) {

    Way cool!

    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: use HTML; # !!!
by dws (Chancellor) on Jul 26, 2002 at 17:38 UTC
    use HTML; print <aol>, "that's sick! :)", </aol>;
      Agreed, sick sick SICK!!

      ...I love it.

Re: use HTML; # !!!
by RMGir (Prior) on Jul 26, 2002 at 21:18 UTC
    You're already being really evil by writing this (or using it!), so what's a bit of anti-social coding?
    package HTML; #force warnings on, in case user "forgot" to... :) $^W++; # rest exactly as japhy wrote it

Re: use HTML; # !!!
by BrowserUk (Patriarch) on Jul 26, 2002 at 21:33 UTC

    Evil? Maybe...but it beats the pants off of CGI poetry mode.

    <itsy-bitsy-tiny>Is this really so evil? Or am I just too (dumb|new|unperlish) to see the dangers?</itsy-bitsy-tiny>
Re: use HTML; # !!!
by strfry() (Monk) on Aug 05, 2002 at 19:15 UTC
    this has an interesting side effect, such as evidenced in this one-liner: perl -MHTML -e 'use warnings;use CGI qw/:cgi/; my $cgi = new CGI; print $cgi->header(-type => "text/html"),<html>,<head>,<title>,"Yuck",</title>,</head>,<body>,<tt>,"hello world",</tt>,</body>,</html>, "\n";' in order to get this to work as it should, i'm forced to make two separate print calls.

    whether this (bug|feature) makes this module more or less evil is best left to your discretion. (:

Re: use HTML; # !!!
by Anonymous Monk on Jul 28, 2002 at 22:55 UTC
    Move the $SIG{__WARN__} setting into import and have a sub unimport { delete $SIG{__WARN__} } (untested)
Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://185604]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-09-30 13:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found