#!/usr/bin/perl # # manpath -- intuit manpath based on path envariable # tchrist@cs.colorado.edu # verbose ugly version. use the other one instead. ### put colon-separated $PATH into a list @bin_path = split /:/, $ENV{PATH}; ### start empty... @manpath = (); ### traverse list this one at a time foreach $path_component (@bin_path) { ### make sure the first char isn't a dot if (substr($path_component, 0, 1) ne ".") { ### make a copy $man_component = $path_component; ### change the last part after the slash to "man" $man_component =~ s/[^\/+]*$/man/; ### does such a directory exist? if (-d $man_component ) { ### but have we already dealt with it? if ( $already_seen{$man_component} == 0 ) { ### append it to the list @manpath = ( @manpath, $man_component ); ### remember we have seen it already $already_seen{$man_component} = 1; } } } } $colon_separated_version = join ":", @manpath; print $colon_separated_version; print "\n";