Ready to Start Your Career?

Tutorial: Book Search Perl Application Code

Bmsr256 's profile image

By: Bmsr256

September 18, 2017

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:`#!/usr/bin/perluse 5.12.0;use strict;use LWP::Simple;print "Enter a book: ";my $book = ;my $url = join('_' , split(' ', $book));my $url = "https://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 =~ /(.*)</th>/){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 ""){$i++;}else{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.
Schedule Demo