Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Version with full quoting/punctuation support' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Version with full quoting/punctuation support
Authored by: jvinocur on Jun 06, '07 04:19:15PM
I've long been using the code below with lynx for quick command-line based searches. It takes search terms as command-line arguments, handles quoting, and correctly escapes a wide range of punctuation (since things like apostrophes are not permitted in URLs).

#!/usr/bin/perl -w
use strict;

# Original by Ilmari Karonen in <>
# Modifications by Jeffrey M. Vinocur

my $u = '';
if (@ARGV) {
  foreach (@ARGV) {
    s/[^ \w]/sprintf '%%%02X', ord $&/eg;  # escape non-alphanum
    if( s/ /+/g ) { $_ = "\"$_\"" };
  $u .= "search?q=" . (join '+', @ARGV);

exec 'open', $u;

[ Reply to This | # ]