.: monkey-mind :.

sheep go to heaven, goats go to hell

Converting relative pathnames to absolute pathnames

The File::Spec module has the rel2abs() subroutine that converts a relative filename to an absolute path. However, it does not remove “./” and “../” components from the path. This is ugly. I wrote an alternative that fixes this. Please note the following:

  • This only works reliably for UNIX-like paths.
  • Even though the implementation of File::Spec is a bit weird, it's not wrong.

Download rel2abs.pl

View rel2abs.pl (non-popup).

If you run the abs2rel.pl script you get the following results:

$ perl rel2abs.pl
./some/../or/../all /here/../there/../anywhere/but/../../here
rel2abs(): /here/all
File::Ext->rel2abs(): /here/../there/../anywhere/but/../../here/some/../or/../all