Perl and Elinks Search from script to terminal

I was Googling for some neat things to do with Perl (I have a pile of scripts in /usr/local/bin), when I thought, hey!? Why not use Perl to search Google? I’ve already started to use Elinks terminal web browser,(available in all Linux repos) so obviously any scripts that mean I am just one command away from finding any needed info would be a bonus.

I decided to call this script “goose”, yeah, I know lol! GooSe as in GOOgle SEarch.

sudo vim /usr/local/bin/goose

Add this:

#!/usr/bin/perl -w

# Created by Rich Scadding 02/08/2010

$browser = “/usr/bin/elinks”;

exec $browser, “http://www.google.com/advanced_search” unless @ARGV;

for ( @ARGV ){ s/.*/%22mce_markeramp;%22/ if y/ /+/; $s .= $s?”+$_”:”$_”; }

# $ENV{LANG} = “en_US.UTF8”;

#!/usr/bin/perl -w# Created by Rich Scadding 02/08/2010$browser = “/usr/bin/elinks”;
exec $browser, “http://www.google.com/advanced_search” unless @ARGV;
for ( @ARGV ){ s/.*/%22mce_markeramp;%22/ if y/ /+/; $s .= $s?”+$_”:”$_”; }
# $ENV{LANG} = “en_US.UTF8”;exec $browser, “http://www.google.com/search?num=30&hl=en&as_qdr=all&q=$s&btnG=Google+Search”

Now take ownership with chown and chmod -x it to run it from the terminal.

EXAMPLE: goose linux-hardcore

Thanks to Ben Okopnik for Perl inspiration ( http://okopnik.com/ ) He has a lot of scripts and articles  floating around the net which are great to learn from. ie. http://linuxgazette.net/134/okopnik.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s