Normalizing a URL with Parse::Yapp

For Perl Weekly Challenge 017 I used Parse::Yapp to detect and print the components of a URL. In order to normalize a URL much of the same code can be re-used to parse the URL with he difference being rather than printing the components applying the various normalization rules.

The Code

Wrapper

All the logic is really in the Grammar file which is called by the small wrapper program.

Grammar

Sample Run

$ perl -Iperl5 perl5/ch-2.pl
jdbc://user:password@localhost/pwc?profile=true

Discussion

The use of Parse::Yapp for this is still somewhat of an over engineering exercise since most all of the work is done by the lexing code. In other words, this could more or less just as easily be done but the same set of regular expressions. That said, if nothing else we gain a nice level of code organization! 

I only implemented a few of the normalization rules. Performing normalization to full generality should be straightforward.

Comments for this post were locked by the author