Tutorial: Book Search Perl Application Code

September 18, 2017 | Views: 3799

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Today, I want to show you a book search source code written in Perl. Perl is a very useful and powerful programming language like Python, except Perl still remains on lots of Unix-like operating systems.

This application searches for information on some web sites. I put Wikipedia, but you can change this with whatever you want.

The code is posted here:

use 5.12.0;
use strict;
use LWP::Simple;

print "Enter a book: ";
my $book = ;
my $url = join('_' , split(' ', $book));
my $url = "http://en.wikipedia.org/wiki/".$url;
print "Data extracted from $urln";
my $content = get $url;
die "No such URL or too many results.n" unless defined $content;
my @tags = split ('n',$content);

foreach my $x (@tags){
if( $x =~ /

print "n".$1;
if( $x =~ /.*(.*)</a>.*</th>/){
print "n".$1;
if( $x =~ /([wsd,-/.]+).*</td>/){
print ": ".$1."n";
if( $x =~ /.*(.*)</a>.*(</td>)?/){
print ": ".$1."n";
if($x =~ /</table>/){ last;}

print "Plot summary: n";

my $i;
my $aux = 0;

for($i = 0; $i < @tags; $i++){
if( $tags[$i] =~ /plot/i ){
if( $aux == 0) {$aux = 1;}
else {$i++; last;}

until( $tags[$i] =~ /mw-headline/ ){
$tags[$i] =~ s/<[/api].*?>//g;
$tags[$i] =~ s/<div.*>//g;
if($tags[$i] eq ""){
print "$tags[$i++]nn";

I hope this code is useful to you and helps you see how you can search for information. It is also a guide to help you learn Perl.

Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
1 Comment
  1. Thank you!

Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Support Cybrary

Donate Here to Get This Month's Donor Badge


We recommend always using caution when following any link

Are you sure you want to continue?