in reply to Road to a readable path
$ perldoc hpath
=head1 NAME B<hpath> - Human-readable print of Unix PATH variable =head1 SYNOPSIS hpath [name] Options: name Name of an environment variable =head1 DESCRIPTION Prints each item of a path-type environment variable onto its own line +. Useful for displaying PATH variable, for example. A path-type variabl +e is really any variable which is a colon-separated list. Takes as input an environment variable name. Input need not be all upper case. However, the actual variable name m +ust be all upper case. Input need not be the full variable name. However, the abbreviated in +put must allow for "PATH" to be appended to it. For example, "man", "MAN", "manpath" and "MANPATH" will all resolve to "MANPATH". If no input is given, the default is "PATH". Output is STDOUT. =head1 EXAMPLES Print the value of the PATH environment variable, one directory per li +ne: hpath Print the value of the MANPATH environment variable: hpath man Print the value of the LD_LIBRARY_PATH environment variable: hpath LD_LIBRARY_PATH =cut use strict; use warnings; my $name = (@ARGV) ? uc shift : 'PATH'; # If environment variable does not exist, try appending "PATH" to its +name: my $path_var = exists $ENV{$name} ? $ENV{$name} : $ENV{$name . 'PATH'} +; if (defined $path_var) { my @list = split /:/, $path_var; print "$_\n" for @list; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Road to a readable path (unix)
by Tanktalus (Canon) on Apr 15, 2009 at 14:48 UTC | |
by parv (Parson) on Apr 15, 2009 at 14:56 UTC | |
by pmonk4ever (Friar) on May 13, 2009 at 22:42 UTC | |
by parv (Parson) on Apr 15, 2009 at 14:54 UTC | |
|
Re^2: Road to a readable path (unix)
by John M. Dlugosz (Monsignor) on May 11, 2009 at 21:00 UTC |