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

Hi there. Im doing this pretty simple script to create folder acording to lines from a txt file.
#!/usr/local/bin/perl @arValores = (); $vDirectorio_read = "txt_entrada.txt"; $vDirectorio_write = "c:\\Datos_dms"; $vPermisos = 0777; open (LECTOR, "<$vDirectorio_read") or die "Entrada nanay"; while (<LECTOR>) { if (/(.+?)/) { $vTemp = $_; push @arValores, $vTemp; #print "$vTemp\n"; } } close LECTOR; mkdir $vDirectorio_write, oct($vPermisos); foreach $vTemp2 (@arValores){ print "$vTemp2\n"; mkdir "c:\\datos_dms\\$vTemp2\n" or warn "No se ha podido crear el + directorio $vTemp2\n"; } exit 0;
I dont know why this code doesn't create me the dirs!!! anyone can help a nerd as me ? thanks!

Replies are listed 'Best First'.
Re: Whats its bad here?
by almut (Canon) on Sep 25, 2009 at 13:26 UTC

    oct() expects a string.  In your case, $vPermisos already holds the octal value (Perl parses a bare 0777 as an octal number)... so no need for oct() with mkdir().  Or if you use it, set $vPermisos = "0777"; (note the quotes).

    (As you have it, you'd end up with 0511, as the implicit number-to-string conversion in oct() would produce the decimal number 511 represented as the string "511", which oct() then obediently converts to the octal 0511 ...)

Re: Whats its bad here?
by ccn (Vicar) on Sep 25, 2009 at 12:32 UTC
    use strict; use warnings;

    check result codes and $!

    At least:

    mkdir "c:\\datos_dms\\$vTemp2" # NOTE: \n is eliminated at the +end of string! or warn "No se ha podido crear el directorio $vTemp2: $!\n";
      i only receive as warning:
      Global symbol "$vTemp2" requires explicit package name at C:\directori +o_creator.cgi line 29.
      im still founding anything that can help me.

        That's no warning, that's an error message. Your program doesn't even start, because Perl found an error in it.