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
From:
Aristotle Pagaltzis
Date:
May 12, 2013 10:26
Subject:
Re: [perl #117969] use POSIX emits multiple warnings if used after"Cwd"
Message ID:
20130512102605.GA5322@fernweh.plasmasturm.org
* Linda Walsh <perlbug-followup@perl.org> [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/postest.pl 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About