Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use URI::Heuristic; use vars qw( $url ); $|++; # Global vars... my $plugin_dir = "/usr/lib/cgi-bin/comix-plugins"; # Set up the useragent, to be used by all plugs. my $agent = LWP::UserAgent->new; $agent->agent("Daily Comix/0.1"); if ( param() ) { &do_this; } else { &print_main; } sub do_this { print header; print start_html(-Title=>"Comix",-BGCOLOR=>'white'); foreach (param) { if ( open(PLUGIN, "$plugin_dir/$_") ) { while (<PLUGIN>){ if (/^#/) { next } my ($key, $val) = split(/=/,$_,2); if (lc($key) eq 'title') { print "<B>$ +val</B><BR>\n"; } if (lc($key) eq 'url') { $url = $val; +print "<I>$url</I><BR>\n"; } if (lc($key) eq 'code') { while () { (my $line = <PLUGIN>); $val .= $line; if ($line =~ /^}/) { l +ast; } } &get_comic( $val ); } } close(PLUGIN); } else { print "<BR><B>There was an error processing $p +lugin_dir/$_</B><BR>\n"; } print "<BR><BR>"; } print end_html; } sub print_main { print header; print start_html(-Title=>"Comix",-BGCOLOR=>'white'); &list_plugins; print "<BR><BR>"; print end_html; } sub list_plugins { print qq(<CENTER><TABLE><TR><TD>); print qq(<FORM ACTION=" +"><BR>\n); if ( opendir(PLUGINS, $plugin_dir) ) { while ( defined( my $file = readdir(PLUGINS) ) ) { if ( $file =~ /^\.{1,2}$/) { next; } open (CONFIG, "$plugin_dir/$file") or die "Cou +ldn't open: $!\n"; while (<CONFIG>) { if (/^#/) { next } my ($key, $val) = split(/=/,$_,2); chomp($val); if (lc($key) eq 'title') { print qq(<INPUT TYPE=CHECKBOX +NAME=$file VALUE=$file> ); print $val, "<BR>\n"; } } } closedir(PLUGINS); print qq(<INPUT TYPE=SUBMIT VALUE="Show comix">); } else { print "Error opening directory: $!\n"; } print qq(</TD></TR></TABLE></FORM>) } sub get_comic { $url = URI::Heuristic::uf_urlstr($url); my $req = HTTP::Request->new(GET => $url); $req->referer(""); my $response = $agent->request($req); if ($response->is_error) { print "Oops... there was an error processing the reque +st<BR>"; print "<DD>", $response->status_line; } else { my $content = $response->content; eval $_[0]; print $@ if $@; } } Configuration file: Title=User Friendly Daily Strip URL= Code={ $content =~ m/(<IMG ALT="Latest Strip" .+?>)/sig; print $1, "<BR>\n"; }

In reply to Daily Comix by Arjen

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (6)
    As of 2018-05-23 17:57 GMT
    Find Nodes?
      Voting Booth?