in reply to How to find code written by smart people

System calls should make you a little nervous. It seems from the context of your post that you chose a system call because Perl's mkdir doesn't do what mkdir -p does on a Unix system. Here's a more-Perlish version that will work on most platforms (not just Unix):

#!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw(splitpath catdir rel2abs); # mkdir -p emulator, call with this.pl /path/to/create my $path = rel2abs(shift @ARGV); my $place = ''; foreach my $dir ( splitpath($path) ) { $place = catdir($place, $dir); (-d $place) || (mkdir $place, 0755) or die "Problem making $place: + $!"; }
<radiant.matrix>
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Replies are listed 'Best First'.
Re^2: How to find code written by smart people
by Hue-Bond (Priest) on Aug 25, 2006 at 17:16 UTC

    Why not use File::Path?

    $ ls foo ls: foo: No such file or directory $ perl -MFile::Path -e 'mkpath "foo/bar/baz"' $ ls -d foo/bar/baz foo/bar/baz/

    Update: Err, forget it. It's already been pointed out.

    --
    David Serrano

      Because of this line in File::Path's POD:

      It returns a list of all directories (including intermediates, determined using the Unix '/' separator) created.

      That raises a concern that I'd have to pass mkpath a UNIX-style path -- the snippet I posted will accept any form supported by File::Spec::Functions. I like that better.

      <radiant.matrix>
      A collection of thoughts and links from the minds of geeks
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet