Closed p5pRT closed 20 years ago
use Cwd qw{ chdir getcwd fast_abs_path }; print "subdir ./0 exists\n" if -d '0'; print "./0 abs path=" . fast_abs_path( '0' ) . "\n"; chdir( '0' ); print "wd now:" . getcwd() . "\n";
Output:
subdir ./0 exists ./0 abs path=/home/laune/ppt/make wd now:/home/laune
These errors come from the lines in Cwd.pm:
sub fast_abs_path { my $cwd = getcwd(); my $path = shift || '.'; ^^^^^^^^ ... sub chdir { my $newdir = shift || ''; # allow for no arg (chdir to HOME dir) ^^^^^^^^
These errors come from the lines in Cwd.pm:
sub fast_abs_path { my $cwd = getcwd(); my $path = shift || '.'; ^^^^^^^^ ... sub chdir { my $newdir = shift || ''; # allow for no arg (chdir to HOME dir) ^^^^^^^^
Thanks for the bug report.
(Sidenote: there are undoubtedly more of these. The oh-so convenient true-false rule of Perl cannot unfortunately be extended to file/directory names. Saying 'but no one will ever use "0" as a f/d name' is not that different from saying 'but no one will ever try to follow the null pointer' or 'but no one will ever divide by zero'...if the domain/range of a variable contains illegal values or other discontinuities\, someone *will* some day try to use them.)
These errors come from the lines in Cwd.pm:
sub fast_abs_path { my $cwd = getcwd(); my $path = shift || '.'; ^^^^^^^^ ... sub chdir { my $newdir = shift || ''; # allow for no arg (chdir to HOME dir) ^^^^^^^^
Thanks for the bug report.
(Sidenote: there are undoubtedly more of these. The oh-so convenient true-false rule of Perl cannot unfortunately be extended to file/directory names. Saying 'but no one will ever use "0" as a f/d name' is not that different from saying 'but no one will ever try to follow the null pointer' or 'but no one will ever divide by zero'...if the domain/range of a variable contains illegal values or other discontinuities\, someone *will* some day try to use them.)
Just because you can have pathnames starting with "-" doesn't mean you can't remove then with /bin/rm either. :-) That's why people pass them as "./-"\, for example.
However\, your point is taken: a *library* function oughtn't do that\, and should accept any string. C\<@_ ? shift : "."> is a more normal idiom there.
--tom
Tom Christiansen wrote:
Just because you can have pathnames starting with "-" doesn't mean you can't remove then with /bin/rm either. :-) That's why people pass them as "./-"\, for example.
Tsk tsk.
$ touch ./- $ ls - $ /bin/rm -- - $ ls $
:-)
Alan Burlison
Just because you can have pathnames starting with "-" doesn't mean you can't remove then with /bin/rm either. :-) That's why people pass them as "./-"\, for example.
Tsk tsk.
$ touch ./- $ ls - $ /bin/rm -- - $ ls $
Ah\, but "./-" doesn't require special-purpose aurgment parsing\, which is why it's the more general solution.
--tom
Tom Christiansen wrote:
Ah\, but "./-" doesn't require special-purpose aurgment parsing\, which is why it's the more general solution.
From the getopts(3C) manpage:
The getopt() function returns the next option letter in argv that matches a letter in optstring. It supports all the rules of the command syntax standard (see intro(1)). Since all new commands are intended to adhere to the command syn- tax standard\, they should use getopts(1)\, getopt(3C) or getsubopt(3C) to parse positional parameters and check for options that are legal for that command. ... The special option "--" (two hyphens) may be used to delimit the end of the options; when it is encountered\, EOF is returned and "--"' is skipped. This is useful in delimiting non-option argu- ments that begin with "-" (hyphen).
So any properly written command will already have this behaviour.
Yes\, I'm just being unnecessarily pedantic.
But it *is* fun to be a pedant sometimes ;-)
So any properly written command will already have this behaviour.
It's difficult to imagine that these folks seriously imagine that *all* "proper" programs *shall* use the libc getopts functions. After all\, not all programs are written in C! And even if they were\, it's not like you can are forbidden from making an a.out without linking to getopts\, which is the only way to make that so.
Personally\, I might be more apt to use getopts in a C program than a Perl one\, where it's so easy not to. But historically\, I've never bothered. Too easy to avoid.
--tom
On Mon\, 28 Aug 2000\, Jarkko Hietaniemi wrote:
These errors come from the lines in Cwd.pm:
sub fast_abs_path { my $cwd = getcwd(); my $path = shift || '.'; ^^^^^^^^ ... sub chdir { my $newdir = shift || ''; # allow for no arg (chdir to HOME dir) ^^^^^^^^
Thanks for the bug report.
(Sidenote: there are undoubtedly more of these. The oh-so convenient true-false rule of Perl cannot unfortunately be extended to file/directory names. Saying 'but no one will ever use "0" as a f/d name' is not that different from saying 'but no one will ever try to follow the null pointer' or 'but no one will ever divide by zero'...if the domain/range of a variable contains illegal values or other discontinuities\, someone *will* some day try to use them.)
shift ?? '';
*duck* :-)
Tom Christiansen wrote:
So any properly written command will already have this behaviour.
It's difficult to imagine that these folks seriously imagine that *all* "proper" programs *shall* use the libc getopts functions. After all\, not all programs are written in C! And even if they were\, it's not like you can are forbidden from making an a.out without linking to getopts\, which is the only way to make that so.
It is a POSIX thing. If you don't have the behaviour documented in getopt(3C) and intro(1)\, Rule 10 you aren't POSIX compliant. Watch out - your willy will drop off if you aren't POSIX compliant. You of all people should know that already.
Other like bugs (assuming that a file/dirname cannot be "0") might exist in the core modules.
Migrated from rt.perl.org#3906 (status was 'resolved')
Searchable as RT3906$