O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An Example: Image Extractor

Let's finish up with an example of a pretty hefty regular expression (two of them, actually), used inside a Perl script. This script takes an HTML file as input, ranges over the file and looks for embedded images (using the <img> tag in HTML). It then prints a list of the images in that page, printing a list of the various attributes of that image (its location, width or height, text alternative, and so on). The output of the script will look something like this:

---------------
Image:  title.gif
   HSPACE: 4
   VPSACE: 4
   ALT: *
---------------
Image: smbullet.gif
   ALT: *
---------------
Image:  rib_bar_wh.gif
   BORDER: 0
   HSPACE: 4
   WIDTH; 50
   HEIGHT: 50
   ALT: --

If you're not familiar with HTML, the <img> tag can be embedded ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required