zdm has asked for the wisdom of the Perl Monks concerning the following question:

Hello. Can somebody explain, why perl produce warning in following code:
use warnings; mkdir( 'aaaa', () );

Replies are listed 'Best First'.
Re: Unexpected warning in mkdir
by jeffa (Bishop) on May 12, 2015 at 17:44 UTC

    mkdir FILENAME,MASK mkdir FILENAME
    You are passing an undefined value for the second value. Don't do that. :)

    use warnings; mkdir( 'aaaa' );

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      You are passing an undefined value for the second value.

      That statement jumped out at me because even though in this particular case it's absolutely correct, with Perl's default behavior for sub arguments and in the absence of prototypes it wouldn't be. So just to go into more detail: Normally, the empty list at the end of the argument list, as in somefunc("aaaa", ()), would get flattened and all the sub somefunc would see in its @_ is "aaaa" and nothing else. However, in this case mkdir has a prototype of _;$ which is what causes the extra () argument to appear in @_ as undef.

Re: Unexpected warning in mkdir
by GotToBTru (Prior) on May 12, 2015 at 19:14 UTC

    I get:

    Use of uninitialized value in mkdir at uw.pl line 3.

    Speaks for itself, does it not? Something that requires a value was left undefined.

    Dum Spiro Spero
    A reply falls below the community's threshold of quality. You may see it by logging in.