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

When running a program I would like to store the various outfile sorted in subfoldes named according to which files are in the subfolder. So my question is basicly: How do I create subfolders and how do I print to subfolders? Thank you for any help.

2006-04-02 Retitled by planetscape, as per Monastery guidelines: one-word (or module-only) titles pose a hazard to site navigation
Original title: 'Subfolders'

Replies are listed 'Best First'.
Re: How do I create subfolders?
by Corion (Patriarch) on Apr 02, 2006 at 08:13 UTC

    The mkdir function creates directories (which I assume are what you mean by "subfolders"). The open function can open files even if you prepend a path to them. If you want to create multiple directories in one go, have a look at File::Path.

    use strict; use warnings; my $outdir = "output"; if (! -d $outdir) { warn "Creating '$outdir'"; mkdir $outdir or die "Couldn't create '$outdir': $!"; }; my $outname = "$outdir/test.txt"; open my $outfile, ">", $outname or die "Couldn't create '$outname' : $!"; print $outfile, "Hello World\n";
      If you want to create multiple directories in one go, have a look at File::Path.
      Corion is not saying it with so many words, but he is talking about the function mkpath(), in File::Path, which comes with Perl.
Re: How do I create subfolders?
by murugu (Curate) on Apr 02, 2006 at 14:56 UTC
Re: How do I create subfolders?
by kgraff (Monk) on Apr 03, 2006 at 00:03 UTC

    To answer the second part of your question, how to navigate the directories you create, the chdir command may be helpful to change your working directory.