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

Dear Masters,
In my linux, I want to create 20 empty directories.
dir1 ... dir20
Is there a quick way to do it with Perl? One-liner?

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re: Creating Multiple Empty Directories with Perl
by ikegami (Patriarch) on Sep 28, 2005 at 06:34 UTC
Re: Creating Multiple Empty Directories with Perl
by samtregar (Abbot) on Sep 28, 2005 at 06:34 UTC
    With File::Path:

       perl -MFile::Path -e 'mkpath([map { "dir$_" } (1 .. 20)])'

    Or without:

       perl -e 'system("mkdir dir$_") for (1 .. 20)'

    -sam

      Why are you using system? Perl has a mkdir function.

      Also, using mkpath is overkill if all directories are being created at the same level.

        You know, I asked myself the same question when I saw the other replies. I guess I forgot it was there! I always use File::Path out of laziness. Who wants to worry about how many levels need to be created?

        -sam

Re: Creating Multiple Empty Directories with Perl
by halley (Prior) on Sep 28, 2005 at 14:31 UTC
    I know everyone's happy to use Perl for everything, but this is overkill here. GNU's mkdir(1) takes multiple arguments. If the desired directory names are truly a numeric range, then you can use seq(1).
    mkdir `seq -f dir%g 1 20`

    --
    [ e d @ h a l l e y . c c ]

      mkdir dir{1..20}
Re: Creating Multiple Empty Directories with Perl
by gube (Parson) on Sep 28, 2005 at 06:36 UTC

    Hi,

    Use the module File::Path in that module there is a function called mkpath, within that you may give the directories you want to create. for eg: mkpath(/root/folder/folder/folder)

Re: Creating Multiple Empty Directories with Perl
by blazar (Canon) on Sep 28, 2005 at 09:01 UTC
    perl -e 'mkdir "dir$_" for 1..20'
Re: Creating Multiple Empty Directories with Perl
by lidden (Curate) on Sep 28, 2005 at 06:35 UTC
    perl -wle 'for(1..20){system "mkdir dir$_"}'