Omg this is like magic :D Or like a Christmas present. It does what I want, yes. Although I don't understand some bits, so if you could be so kind and explain them you'd be helping me fill one more page in my Perl notebook! I need to understand how stuff works otherwise I'll soon be asking the same things again and annoy you all.

So:

1. my $length = $total_length - length($prefix);

my $format = "${prefix}%0${length}d";

^

What is happening here? So in the first line, you subtract the length of the prefix from the total length, which is 6. Ok, I got that. But then in the second line, I don't get it. Why "${prefix}" and not "{$prefix}"? Oh I think I just got the next bit: "%0${length}d" -> that says we need "length"-many zeros, whatever the value of $length is from above.

2. return map sprintf( $format, $_ ), $from .. $to;

^

I'm really lost with that one. If the for loop that goes through @dirs already does the job, shouldn't return map be before the for loop? Also why is it return map and not map?

3. Actually in general what confused me is that I thought Perl reads the script line by line from top to bottom. Now in this example we first use make_path and then set the subroutine. Shouldn't the subroutine be on top of everything else?

I know you probably get this all the time but I do apologise for the silly questions - I have already started reading the stuff on subroutines, map, make_path and so on, but a bit of discussion helps greatly.

Thank you for the help, this page is amazing for solving Perl problems and answering questions.


In reply to Re^2: make_path for creating directory tree by fasoli
in thread make_path for creating directory tree by fasoli

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.