in reply to Re^2: Working with a unkown number of arrays
in thread Working with a unkown number of arrays

Yes, that's much closer! Let me correct a couple of small nits:

        if ($_ =~ /\d*/){    ##if directory name is a number

The $_ is unnecessary there. Be very careful with that regex, though; it matches strings with zero or more digits. I think you might do better with if (/\.\d+/) {.

foreach (@directories) { my $dir_num = $_;

I see this pattern often and don't understand it. It's much simpler to write:

for my $dir_num (@directories) {

Of course, you can still use foreach there in place of for if you want, but they're synonyms, so I use the shorter one.

Replies are listed 'Best First'.
Re^4: Working with a unkown number of arrays
by jdporter (Paladin) on Feb 05, 2007 at 20:13 UTC
    /\.\d+/

    And based on the patterns (examples) he gave before, I don't think we can assume there's a dot, but we do know the numbers are at the end. Therefore:

    /\d+$/

    Furthermore, the whole thing can be reduced to this:

    my @directories = grep { /\d+$/ and -d $_ } readdir DIR;

    although that doesn't do the print. But I don't think that's necessary.