Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Short quines

by Snarius (Sexton)
on Jan 12, 2008 at 00:23 UTC ( [id://662014]=note: print w/replies, xml ) Need Help??


in reply to Short quines

Here's mine quine.
use strict; #yesindeed
use LWP;
use HTTP::Request;
my $ua = LWP::UserAgent::new ('LWP::UserAgent');
LWP::UserAgent::agent ($ua, 'Mozilla/5.0');
my $url = "http://www.perlmonks.org/?node_id=662014";
my $request = HTTP::Request::new ('HTTP::Request', GET => $url);
my $response = LWP::UserAgent::request ($ua, $request);
my $page = $response->content;

my $beginning = q/use strict/;
my $end = q/q.positively./;
$page =~ /($beginning.*$end)/s;
my $code = $1 . "\n";
print $code; 
q!positively!

Replies are listed 'Best First'.
Re^2: Short quines
by jdalbec (Deacon) on Jan 12, 2008 at 15:36 UTC
    If you use <code> tags your quine becomes much simpler:
    use strict; use LWP; use HTTP::Request; my $ua = LWP::UserAgent::new ('LWP::UserAgent'); LWP::UserAgent::agent ($ua, 'Mozilla/5.0'); my $url = "http://www.perlmonks.org/?displaytype=displaycode;node_id=6 +62072"; my $request = HTTP::Request::new ('HTTP::Request', GET => $url); my $response = LWP::UserAgent::request ($ua, $request); print $response->content;
    Also, you don't break formatting for replies to your node.

    Edit: I think you want a question mark after dot-star. Otherwise it's q-positively trivial for me to break your code.

    Edit2: I just realized that, if you put a question mark after dot-star, the end of your regex matches itself. But there are ways around that.

      As the title of this thread is "short quines", let me shorten that code a bit.

      use LWP::Simple;getprint"http://tinyurl.com/ynp5kp"

      Update: fixed code. It should now work.

      Update 2012-05-24:</c> see also Usually J.A.P.H..

      I tried using <code. It renders > as & gt; or something. I actually tried to eliminate the >'s from my code, which is why there are lines like LWP::UserAgent::request ($ua, $request); instead of $ua->request ($request);.

        I'm quite sure that the displaytype=displaycode cgi argument makes perlmonks return the code as plain text, not HTML, so the angle brackets shouldn't be a problem.

        Let me try.

        use warnings; use strict; my $u = "http://perlmonks.com/?node_id=662172;displaytype=displaycode" +; use LWP; print LWP::UserAgent->new->get($u)->content;
Re^2: Short quines
by Your Mother (Archbishop) on Jan 12, 2008 at 03:25 UTC

    It seems to be broken...

    use strict; my $code = "death to dot star!\n"; print $code;

    update: jdalbec already re-broke the code. Just noting it was silently updated -- boo! -- after I showed it broken the first time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-20 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found