in reply to Re^3: make_path for creating directory tree
in thread make_path for creating directory tree

for my $molecs (@molecs) { my $structs = shift @structs; ## Add for my $steps (@steps) { make_path "/media/RAIDstorage/home/results/$structs/$molecs/$steps +"; } }
poj

Replies are listed 'Best First'.
Re^5: make_path for creating directory tree
by Anonymous Monk on Jan 22, 2016 at 17:54 UTC

    Hi poj, thank you for the quick reply! Just so I'm sure I'm trying this correctly, do you mean I should use only this loop? Or, add this loop to my code?

    I've tried it both alone and combined with one of my loops (below) (this one)

    for $structs (@structs) { make_path "/media/RAIDstorage/home/results/$structs"; }
    but in both cases it behaves weird. It still complains for the same uninitialized value, but it does go ahead, in both cases, and creates some directories, however it's not what I want to get in the end.

    It puts AB0001 in struct1 (correct) but instead of putting BC0001 in struct2, it puts AB0002. I tried increasing the lengths of the string to check for such a behaviour. It's probably wrong because I either did something wrong or I failed to explain what I want to get in the end. I want all AB0001, AB0002, AB0003 and so on to go into struct1 and all BC0001, BC0002, BC0003 and so on, to go into struct2

    I'm really, really sorry to be a pain - if anyone can point to what might be happening...? I don't get it because $structs is initialised so I don't know why it's complaining. And also it's confusing me how to get the subdirectories in correctly.

      Sorry, one more update. It runs without an error and puts AB0001 in struct1 and BC0001 in struct2 if the number for AB and BC is only from 1 to 1. If I try AB and BC with a bigger number, from 1 to 2, it returns the uninitialized value error and it runs wrong: it puts AB0001 in struct1 and AB0002 in struct2 - ignoring BC completely. Isn't that strange?

      I'm referring to this

      @molecs = ( dir_tree( 'AB', 6, 1, 1 ), dir_tree( 'BC', 6, 1, 1 ), # dir_tree( 'XZ', 6, 1, 4 ), # dir_tree( 'XY', 6, 1, 4 ), # dir_tree( 'QU', 6, 1, 4 ), # dir_tree( 'QE', 6, 1, 4 ), );

      So if I change "from...to" to "1 to 2", it does the above.

        Try this, if OK replace the print statements with make_path

        #!perl use strict; use warnings; use File::Path qw(make_path); # Parent structure directory. my @structs = ( dir_tree( 'struct', 7, 1, 2), ); # Subfolder molecule directory. my @molecs = ( [dir_tree( 'AB', 6, 1, 3 )], # note [] [dir_tree( 'BC', 6, 1, 3 )], ); # Subfolder steps directory. my @steps = dir_tree( 'S', 6, 1, 2 ); for my $structs (@structs) { #mkdir "/media/RAIDstorage/home/results/$structs"; print "/media/RAIDstorage/home/results/$structs"; print "\n"; my $ar = shift @molecs; for my $molecs (@$ar) { for my $steps (@steps) { #make_path "/media/RAIDstorage/home/results/$structs/$molecs/$st +eps"; print "/media/RAIDstorage/home/results/$structs/$molecs/$steps"; print "\n"; } } } # Define subroutine here. sub dir_tree { my ( $name, $total_length, $from, $to ) = @_; my $length = $total_length - length($name); my $format = "${name}%0${length}d"; return map sprintf( $format, $_ ), $from .. $to; }
        poj