Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Issue with capturing a string after splitting on "/"

by didess (Sexton)
on Feb 05, 2009 at 23:44 UTC ( [id://741746]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found