in reply to Issue with capturing a string after splitting on "/"

Hi ! If your only need is to get the numerical part, I propose this solution :
#!/usr/bin/perl use strict; my $komp_dir ='/Users/mydirectory/Desktop/BioinfDev/SequenceAssemblyPr +oject/KOMP/'; my @komp_dir_content = glob("$komp_dir/*"); my $k_dir; foreach $k_dir(@komp_dir_content) { if (-d $k_dir){ $k_dir =~ s(.*/)(); next if ( $k_dir !~ /^\d+_/); $k_dir =~ s(_.*)(); print "$k_dir\n"; next; } }
I hope it helps ! The problem came from the "use strict" and the loop variable being not declared at main level :

either don't use "use strict" or declare the loop variable (became $k_dir here)

I changed a little variable-names because I think reusing the same name for different usages is an unuseful risk for programs maintenance.

But, of course, you're quite free ...

Replies are listed 'Best First'.
Re^2: Issue with capturing a string after splitting on "/"
by lomSpace (Scribe) on Feb 06, 2009 at 15:46 UTC

    Hi Didess
    You are right about the variable names, but I miss where the
    digit capture occurs?
    Thanks!
    Lom Space