CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
UNIX path regex

 



aceall
Novice

Feb 8, 2010, 7:01 AM

Post #1 of 3 (818 views)
UNIX path regex Can't Post

 

I've recently started using perl. I would like to know the regex to capture the instance along with port number. Lets say "/apps/tomcat-9999" where i am looking for only tomcat-9999. I took a "ps" dump and trying to search for this pattern /\/apps(\/tomcat\-[0-9]*)/ and print $1. This does not seem to work. Any pointers?


shawnhcorey
Enthusiast


Feb 8, 2010, 8:41 AM

Post #2 of 3 (815 views)
Re: [aceall] UNIX path regex [In reply to] Can't Post

You should use File::Spec when working with file and directory names and paths. See `perldoc File::Spec`.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


7stud
Enthusiast

Feb 8, 2010, 12:25 PM

Post #3 of 3 (805 views)
Re: [aceall] UNIX path regex [In reply to] Can't Post


Code
use strict; 
use warnings;
use 5.010;

my @file_names = (
'/usr/hello/world',
'/apps/tomcat-9999',
'/goodbye/world',
);

for (@file_names) { #each file name gets assigned to $_

if ( /\/apps(\/tomcat\-[0-9]*)/ ) { #when no target specified, matches against $_
say $1;
}

}

--output:--
/tomcat-9999



(This post was edited by 7stud on Feb 8, 2010, 12:32 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives