[Israel.pm] Cwd::abs_path and "~"
Offer Kaye
oferk at oren.co.il
Wed Feb 11 08:16:54 PST 2004
>
> ~ is not a real pathname. In C-shell and many other shells (tcsh,
> bash, zsh,
> etc.) it is an alias for the environment variable $HOME. The
> correct syntax
> would be:
>
> abs_path("$ENV{HOME}/some/path");
>
> Regards,
>
> Shlomi Fish
>
Alas, the input is not up to me. I must deal with it, I can't tell the users to write "$ENV{HOME}" instead of "~".
Anyway, problem solved- I used Perl's "glob" function and fed the output from that to abs_path:
Cwd::abs_path( (glob "~/some/path")[0] );
The reason for wrapping glob with ()[0] is the way it behaves in scalar context:
"In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted."
This way I get rid of the undef value...
BTW, I checked, and Perl's "chdir" also doesn't like "~", so this is not a problem specific to Cwd.
----------------------------------
Offer Kaye
More information about the Perl
mailing list