develooper Front page | perl.perl5.porters | Postings from May 2013

Re: [perl #117969] use POSIX emits multiple warnings if used after"Cwd"

Thread Previous | Thread Next
Aristotle Pagaltzis
May 12, 2013 10:26
Re: [perl #117969] use POSIX emits multiple warnings if used after"Cwd"
Message ID:
* Linda Walsh <> [2013-05-12 03:05]:
> #!/usr/bin/perl -w
> use Cwd qw(getcwd cwd abs_path realpath);
> {
> 	no warnings; use POSIX; #>& /dev/null!
> }
> ---
> Gives:
> Subroutine main::getcwd redefined at /tmp/ line 4.
> That's the first problem -- that there are any warnings.

The warning *is* not the problem, the warning tells you *about* the
problem. You explicitly imported `getcwd` from Cwd, then used POSIX
which also exports `getcwd` by default. Thus you overwrote the one you
asked for with another you got implicitly. Now it so happens that the
new `getcwd` you got is functionally identical to the one you lost and
your program will therefore work either way. But there is no inherent
reason for a collision to be harmless like this, therefore the warning
is not noise that one should like to strangle but a heads-up to heed.

The correct fix for your problem is to cease asking either Cwd or POSIX
for `getcwd`, which in the case of POSIX is most feasibly and sanely
achieved by asking POSIX to export only the functions you will require.
(In the name of convenience, its default export list is *huge* and full
of stuff you will never use.)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About