in reply to mkdir with a list variable

mkdir has a prototype of $;$:

perl -we "print prototype('CORE::mkdir')" $;$

This means that the first variable in the call to it will be put into scalar context. Most likely, you have now a subdirectory named "2" in ~/LGRID_Machine/examples, because @a evaluated to the number of elements (2).

To solve your larger problem of calling arbitrary builtins with the appropriate parameters, I think you will have to explicitly pass the parameters:

mkdir $a[0], $a[1];

instead of

mkdir @a;

Creating the appropriate calls can maybe be done by inspecting prototype("CORE::$function"), but some functions (like print) don't even have a prototype because they are super special.

Replies are listed 'Best First'.
Re^2: mkdir with a list variable
by casiano (Pilgrim) on Mar 04, 2008 at 12:17 UTC
    Many, many thanks Corion!

    Casiano

Re^2: mkdir with a list variable
by tirwhan (Abbot) on Mar 04, 2008 at 12:18 UTC

    Update:Ah bollocks, that's exactly what the OP wants to do, ignore me please.

    To solve your larger problem of calling arbitrary builtins with the appropriate parameters, I think you will have to explicitly pass the parameters:
    mkdir $a[0], $a[1];

    That won't work, it'll just create the directory $a[0] with the permissions as per filemask $a[1] (at least that's what it does on my 5.8.8 on Linux, is this different on Windows?)

    To the OP: mkdir expects a single directory name. If you want to create multiple directories just do so in a loop, e.g.

    for my $d (@a) { mkdir $d or die "Couldn't create directory $d: $!"; }

    All dogma is stupid.