Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

use HTML; # !!!

by japhy (Canon)
on Jul 26, 2002 at 17:26 UTC ( [id://185604]=CUFP: print w/replies, xml ) Need Help??

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>"; } 1; __END__ #!/usr/bin/perl -w use HTML; print <html>, <head>, <title>, "This is vile", </title>, </head>, <body bgcolor="#ffffaa">, <tt>, "japhy", </tt>, " is insane.", </body>, </html>, ;

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

    --
    Mike
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. (:

    strfry()
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2025-05-25 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.