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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
UNIX path regex



Feb 8, 2010, 7:01 AM

Post #1 of 3 (1580 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?


Feb 8, 2010, 8:41 AM

Post #2 of 3 (1577 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`.


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

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

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


Feb 8, 2010, 12:25 PM

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

use strict; 
use warnings;
use 5.010;

my @file_names = (

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

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



(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