Achieving the Impossible with Perl
-
Upload
adam-trickett -
Category
Technology
-
view
1.069 -
download
0
description
Transcript of Achieving the Impossible with Perl
![Page 1: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/1.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
1
PerlPerlA Beginner's Guide toA Beginner's Guide to
Achieving The Impossible.Achieving The Impossible.
Adam John TrickettAdam John Trickett
PGP Key: 0x166C4BF0
![Page 2: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/2.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
2
Or...Or...
● Standing on the Shoulders of Giants● Laziness is a Virtue in Perl● Leveraging the power of CPAN
![Page 3: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/3.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
3
An Example...An Example...
● Write a command line script to show the current running times of trains between two stations in the UK.
![Page 4: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/4.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
4
Here Is One IHere Is One IPrepared EarlierPrepared Earlier
![Page 5: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/5.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
5
CPAN Is Your Friend...CPAN Is Your Friend...
● Comprehensive Perl Archive Network● Globally distributed over 253 mirrors● On-line since 26 October 1995● 4247 MiB of data (more in archive)● 6303 Authors● 12652 Modules
● It's all FREE!
![Page 6: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/6.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
6
Web InterfaceWeb Interface
● There are two front end web interfaces:● search.cpan.org● kobesearch.cpan.org
● An upload service for authors:● pause.perl.org
● Testing, quality, bug tracking and more:● cpantesters.perl.org● rt.cpan.org
![Page 7: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/7.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
7
![Page 8: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/8.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
8
![Page 9: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/9.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
9
![Page 10: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/10.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
10
![Page 11: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/11.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
11
![Page 12: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/12.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
12
![Page 13: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/13.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
13
![Page 14: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/14.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
14
Command LineCommand Line
● CPAN comes with it's own installation tool suite called cpan● Search for modules● Download modules● Install modules● Resolve dependencies● Update modules
![Page 15: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/15.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
15
![Page 16: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/16.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
16
Find your moduleFind your module
● Search using the web interface:● Read the documentation● Look at errors and problems● Check the rating● Check how fresh it is
● Download the tarball over the web, or● Install with CPAN if you can – it automatically
resolves dependencies● Carefully study the manpage using perldoc
![Page 17: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/17.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
17
![Page 18: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/18.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
18
![Page 19: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/19.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
19
![Page 20: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/20.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
20
![Page 21: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/21.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
21
The CodeThe Code
#!/usr/bin/perl
use strict;use WWW::LiveDepartureBoards;
my $basing = WWW::LiveDepartureBoards->new({station_code => 'BSK'});my $overton = WWW::LiveDepartureBoards->new({station_code => 'OVR'});my $time = localtime();
print "\nTime Now: $time\n\n";
my @details = $basing->destination('ovr');print "Starting at Basingstoke, going to Overton\n";print_details(\@details, 'OVR');
print "\n";
![Page 22: Achieving the Impossible with Perl](https://reader033.fdocuments.net/reader033/viewer/2022052900/5559a528d8b42aa4288b4b4e/html5/thumbnails/22.jpg)
Version 1.0.0 © Adam Trickett August 2007 Distributed under a creative commons Attribution-NonCommercial-ShareAlike licence.
22
The Code, cont'The Code, cont'
my @details = $overton->destination('bsk');print "Starting at Overton, going to Basingstoke\n";print_details(\@details, 'BSK');
sub print_details { my $details = shift; my $final = shift;
print "Time\tStatus\t\tFinal Destination\n";
foreach my $detail (@$details) { print $detail->{time}, "\t", $detail->{status}, " \t", $detail->{$final}, "\n"; }}