Skip to Content
Perl for Web Site Management
book

Perl for Web Site Management

by John Callender
October 2001
Beginner
528 pages
15h 20m
English
O'Reilly Media, Inc.
Content preview from Perl for Web Site Management

Creating Directories

The first step in writing our HTML files is to make sure that all the directories our script is going to be writing to already exist. If they don’t, the script won’t be able to open files in them for writing. So, we’ll need to check for any of those directories that might be missing and create them if necessary.

In the script, that happens right after the (now-commented-out) debugging section:

# make sure all the directories we'll need exist

my @dirs = ($base_path, "$base_path/alpha", "$base_path/cats",
            "$base_path/listings");

We start by creating a @dirs array that contains a list of all the directories that we want to make sure exist already. As you can see, we’re including in that list the $base_path directory from the script’s configuration section, as well as subdirectories of that directory named alpha, cats, and listings.

Next, we need to add a directory under listings for each letter of the alphabet. We do this with the following block of code:

foreach my $letter ('a' .. 'z') {
    push @dirs, "$base_path/listings/$letter";
}

This uses a foreach loop, but the parentheses have something unusual inside them: Perl’s very cool range operator, which consists of two dots (..) with something on either side of them. The normal way the range operator is used is to return a list of numbers, as in 1 .. 10, which would return a list of the numbers 1 through 10. But it also can return a range of strings, which means the 'a' .. 'z' used in this example returns a list ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Web Client Programming with Perl

Web Client Programming with Perl

Clinton Wong
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

Ken Williams, Dave Rolsky

Publisher Resources

ISBN: 1565926471Catalog PageErrata