Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: fortune

by zeno (Friar)
on Jan 26, 2001 at 14:45 UTC ( #54522=note: print w/replies, xml ) Need Help??

in reply to fortune

Great job on this! I just added this line:
print "Content-Type: text/html\n\n";
as the first line of the script, put the resulting script into my cgi-bin, and set the resulting URL as my startup page for my browser. Now I get strange fortune wisdom every time I fire up my browser! Thanks for making my day just a little more surreal!

Replies are listed 'Best First'.
Re: Re: fortune
by davorg (Chancellor) on Jan 26, 2001 at 15:00 UTC

    Why are you giving it a content type of text/html? Looks like text/plain would be more appropriate - unless to want to change the script to actually output some HTML!


    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      davorg is right! So I modified my original, um, modification to include some nice HTML formatting to it. Here's the new code. Thanks davorg for getting me to fix it! -timallen
      #!/usr/bin/env perl -w use strict; my $quip = ""; { $/ = "%%\n"; rand($.) < 1 && chomp($quip = $_) while(<DATA>); } print "Content-Type: text/html\n\n"; print "<html><head><title>Fortune Teller Says...</title></head>"; print "<body bgcolor=#CCFFFF>"; print "<h3>$quip</h3>" || "<font color=FF0000>Could not get quote</fon +t>"; print "</body></html>"; __END__
      ... followed by the original (hilarious) quips!
        First, I had trouble with __END__, seemed to work better with __DATA__.

        Here is the same thing looking a little more perlish and minus the deprecated FONT tag and BODY attributes and not using header tags to provide large text. Putting style back in using CSS is left as an exercise for the reader.
        #!/usr/bin/perl -w use strict; use CGI qw(:standard); my $quip = ""; { $/ = "%%\n"; rand($.) < 1 && chomp( $quip = $_ ) while(<DATA>); $quip = $quip || 'Doomed! No Fortune Found.'; } print header(), start_html( -title => 'Fortune Teller Says...' ), p( $quip ), end_html(); __DATA__

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://54522]
[PriNet]: quick question... anyone know how to remove all the existing keys in a %hash ? i've tried several options, but when i re-use the hash, some of the "upper" keys that i don't re-use stick and i can't get them to "remove"
[atcroft]: PriNet: %hash = ();? or foreach my $k ( keys %hash ) { delete $hash{$k}; }?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-06-28 02:50 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (619 votes). Check out past polls.