![]() |
|
Perl Monk, Perl Meditation | |
PerlMonks |
Re: Directory Structure.by shmem (Chancellor) |
on Mar 31, 2017 at 13:19 UTC ( #1186621=note: print w/replies, xml ) | Need Help?? |
I tried alot but couldnt able to do that please help me to do that What you didn't try to do is describing your code to yourself; I'll do that for you: You create VEHICLES and change into this empty directory. Fine. Inside this directory you create a directory and change into this empty dirctory. Then, inside this subdirectory, you try to chdir into the directory VEHICLES (which is what the variable $dir holds). This subdirectory doesn't exist in VEHICLES/CARS. Bummer. This part of your code silently fails. Your current working directory stays the same (VEHICLES/CARS). You iterate to the next element in @files. You end up with
which is your current working directory after the loop ends. First thing you should do is checking all your operations for success:
Output:
Aha! there's no such file or directory inside the loop, when you try to chdir to VEHICLES. You realize the two chdir statements inside the loop are bogus and eliminate them:
Then you run your file again. Output now:
So, you should check for existence before making a directory. See -X for the various file testing operators.
Now your code runs and produces the expected structure:
See chdir, mkdir, not, -X, or, die for more information about the added bits.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|