Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Create new directories

by ibaboom (Initiate)
on May 29, 2008 at 14:18 UTC ( [id://689022]=note: print w/replies, xml ) Need Help??


in reply to Re: Create new directories
in thread Create new directories

Here is the code I have so far, I am looping through and getting the directory and making the directories. How do I get the group and owner information from the lines below the directory.

open(FILE,"@ARGV[0"); while (defined ($line = <FILE>)) { chomp $line; if $line =~ /mydir/) { $directory = substr($line, 8); } mkdir $directory, "\n"; }

Replies are listed 'Best First'.
Re^3: Create new directories
by Corion (Patriarch) on May 29, 2008 at 14:22 UTC

    Maybe a good start would be to show the relevant part of the code you already have? Also, it often helps us to help you better if you show exactly where you have the problems.

    Most likely you will then look at File::Path and/or mkdir.

Re^3: Create new directories
by pc88mxer (Vicar) on May 29, 2008 at 16:02 UTC
    One obvious problem -- put the mkdir inside the if statement:
    if ($line =~ /mydir/) { $directory = ... mkdir $directory, 0775; }
    You only want to call mkdir if the line matches.

    Also, passing "\n" to mkdir doesn't make any sense here. The second argument to mkdir is a permission mode mask. See the comments on perldoc -f mkdir for more discussion on how this parameter works.

    Finally, you should get accustom to using the three parameter version of open:

    open(FILE, '<', $ARGV[0]);
    This is much safer.

      and checking an open() for success is even safer:

      open FILE, '<', $ARGV[0] or die "$ARGV[0]: $!\n";

      In cases, that it can't open the file, it won't try to read from an unopened filehandle FILE, but end the script with an error message.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found