Note the mkdir documentation states:

"To recursively create a directory structure, look at the make_path function of the File::Path module."

for example:

#!/usr/bin/perl use strict; use warnings; use File::Path qw(make_path); my $x='x'; my $y='y'; my $dirname = "$x/$y"; make_path( $dirname , { chmod => 0777, }); my $output="$dirname/z.txt"; open ( my $fh, ">", $output ) or die "Cannot open file '$output': $!\n +"; print $fh "\n It's ok.\n"; close $output; print "\n Program is over.\n";

Results:

D:\code>perl path.pl Program is over. D:\code>cd x/y D:\code\x\y>dir Volume in drive D is Data Volume Serial Number is 3241-B96B Directory of D:\code\x\y 22/04/2017 10:39 <DIR> . 22/04/2017 10:39 <DIR> .. 22/04/2017 10:39 13 z.txt 1 File(s) 13 bytes 2 Dir(s) 107,416,027,136 bytes free D:\code\x\y>cat z.txt It's ok. D:\code\x\y>

In reply to Re: How can one create a text file in the subfolder of a folder? by marto
in thread How can one create a text file in the subfolder of a folder? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.