Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Create new directories

by ibaboom (Initiate)
on May 29, 2008 at 13:34 UTC ( #689012=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

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

      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"; }

        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.

        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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-14 10:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found