magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1998 > 02 > Programming with Perl  

Transplanting Absolute and Relative Lengths

Someone once asked me for a tar of a portion of my Web site, in order to read it in on a local disk. At first, I said "no problem, I'll just launch tar right here." But then I realized that while the files would be intact, the links would be a mess. Like most people, I had three kinds of links: absolute; relative, pointing within the tree to be moved; and relative, pointing outside the part to be moved. I needed a file tree in which all internal links (links to other parts of this tree) were relative, so that it didn't matter where it went on my friend's server (or even as a tree of local files accessed with file: URLs). All links outside that tree had to be absolute, so that my friend's browser would just transparently pick up the Web path and run with it.

I started hacking out something with a few regular expressions, but quickly realized I was rebuilding the HTML::Parse module from the wonderful LWP package. I scuttled my earlier effort and decided to make a very powerful and robust program using that module as a base.

The trick with HTML::Parse was to construct a series of "callbacks." As that module is parsing an HTML file, it recognizes start and end tags, comments, and so on. Although I was interested only in the start tags (for the URLs in <A> and <IMG> attributes), I still needed to construct a "passthrough" callback for all the rest.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2