Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Whats its bad here?

by Sombrerero_loco (Beadle)
on Sep 25, 2009 at 12:25 UTC ( [id://797479]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://797479]
Approved by ccn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-19 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found