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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |