Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Because I have always assumed that Google would aggregate tracking information across its various web properties, I have long used Scroogle for most of my web searches. It turns out I was right: every mail message you read, every search you perform, and every page you visit with a Google-served ad or analytics tracker is linked to your unique identity. With Google making Scroogle unreliable lately, I have given Duck Duck Go (implemented in a mixture of Perl and JavaScript) another look, and I have been pleasantly surprised: it gives pretty good results with an uncluttered interface and a sane privacy policy.

It also has an easy-to-use API, without license keys or similar BS. While there are a couple of CPAN modules for this API, they're pretty heavy for such a simple task. Here's a simple script that, on Perl >= 5.14, has no non-core dependencies:

use JSON::PP; use HTTP::Tiny; sub ddg_clean { my $res = shift; for my $k (keys %$res) { delete $res->{$k} if $res->{$k} eq ''; if (ref $res->{$k} eq 'HASH') { ddg_clean($res->{$k}); delete $res->{$k} unless keys %{$res->{$k}}; } elsif (ref $res->{$k} eq 'ARRAY') { ddg_clean($_) for @{$res->{$k}}; delete $res->{$k} unless @{$res->{$k}}; } } } sub ddg { my $q = shift; my $h = new HTTP::Tiny; my $res = $h->get( 'http://api.duckduckgo.com/?' . $h->www_form_urlencode({ format => 'json', q => $q })); die unless $res->{success}; ddg_clean($res = decode_json($res->{content})); $res; } sub INDENT() { ' ' } sub ddg_format { my ($it, $lev) = @_; if (!ref $it) { wrap(INDENT x $lev, INDENT x $lev, $it); } elsif (ref $it eq 'HASH') { join "\n", map { my $val = ddg_format($it->{$_}, $lev+1); if ($val =~ /\n/) { INDENT x $lev . "$_:\n$val"; } else { $val =~ s/^\s+//; INDENT x $lev . "$_: $val"; } } sort keys %$it; } else { join "\n", map { ddg_format($_, $lev+1) } @$it; } } if (!defined caller) { eval 'use Text::Wrap'; print ddg_format(ddg("@ARGV"), 0), "\n"; }

In reply to Sometimes Perl is awesome: Duck Duck Go edition by educated_foo

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found