Downloading Text and Images: Learn Perl By Doing It, Part 3

How to download text and images with just a few lines of Perl.

use strict;
use warnings;

use LWP::Simple;

sub main {
    print "Downloading ...n";
    # Download the specified HTML page and print it to the console.
    # print get(http://localhost:4000/);
    # Download the Cave of Programming home page HTML and save it to "home.html"
    # getstore(http://localhost:4000/, "home.html");
    # Download logo.png from the Internet and store it in a file named "logo.png"
    my $code = getstore(http://localhost:4000/wp-content/themes/squiffy/images/logo.png, "logo.png");
    # Did we get code 200 (successful request) ?
    if($code == 200) {
        print "Successn";
    else {
        print "Failedn";
    print "Finishedn";