in reply to Having trouble returning the correct values from my sub

One thing that is weird is that you call the routine with a parameter $k

my $komp_dir = get_directory($k);

but you're not using that parameter anywhere in the routine

sub get_directory{ my @dirs = glob("C:\\Documents and Settings\\mydirectory\\Desktop\ +\KOMP\\*"); foreach my $maid_dir(@dirs){ if (-d $maid_dir){ # directory check if ($maid_dir=~m%\d+\s[A-Z]%){ # match the dir name return $maid_dir; } } } }

so it will effectively always return the same $maid_dir, i.e. the first directory from @dirs where your regex matches.

Presumably you intended to use that $k somewhere in get_directory ... (?)

Replies are listed 'Best First'.
Re^2: Having trouble returning the correct values from my sub
by lomSpace (Scribe) on Feb 26, 2009 at 22:08 UTC
    No I just want the return values

      Then why pass $k?

      Also, you don't get values, you get exactly one value from get_directory(), because as soon as your regex matches, you're leaving the routine (and thus the foreach loop within the routine)...

        True! I am getting only one value. I will try another for
        loop.