On 4/20/07, Paul LeoNerd Evans <[EMAIL PROTECTED]> wrote:
The requirement for this module came about intially because I was
thinking about how to handle virtual URLs in websites; for example:

  /photos/album12/photo17.jpg

This will fetch the 17th photo from the 12th album, by whatever method
internally is used. Internally, we need to know these values. Trying to
make as generic a system as possible, I came up with the idea that
somewhere in site config, would live a regexp-like pattern to explain
how to parse that. This pattern needs to be reversible - the logic that
generates pages has to be able to construct URLs that give paths to the
files in question.

The format I came upon would look like this:

  '/photos/album${ALBUM:\d+}/photo${PHOTO:\d+}.jpg'

This is just named capturing, isn't it? In perl 5.10:

 qr!/photos/album(?<ALBUM>\d+)/photo(?<PHOTO>\d+).jpg!;
 $url = "/photos/album$+{ALBUM}/photo$+{PHOTO}.jpg";

With my hacky CPAN module for earlier perls:

 use Regexp::NamedCaptures;
 my %photo;
 qr!/photos/album(?<\$photo{ALBUM}>\d+)/photo(?<\$photo{PHOTO}>\d+.jpg!;
 $url = "/photos/album$photo{ALBUM}/photo$photo{PHOTO}.jpg";

Josh

Reply via email to