An Example: Creating Links

Here's a useful example I tend to use a lot in real life: Given a directory full of files that are either GIF or JPEG images (that is, they have .gif, .jpeg, or .jpg extensions), this script will generate an HTML file, called index.html, which contains nothing but links to each of the files. This is a good way to get a whole lot of images up on the Web really quickly without having to spend a lot of time creating HTML files (or it at least provides a basic file you can then edit to make it read better).

The script I wrote for this task uses file handles to open and write to the index.html file, directory handles to read the contents of the current directory, and file tests and regular expressions to match the files ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.