P
Prab_kar
Hi all,
I wonder if this can be done through regex matching.
I have a string of unix path, which can be either
/home/MyAccount/Proj/SubProj or
/home/MyAccount/Proj
2. Just the "Proj" protion if there are no SubProjs.
I tried,
-------------------------------------
#!/usr/local/bin/perl -w
use strict ;
my $string = '/home/MyAccount/Proj/SubProj' ;
# my $string = '/home/MyAccount/Proj' ;
if ( $string =~ m/(.*)\/(.*)\/(.*)$/ )
{
print "Project: $2 \t SubProject: $3\n" ;
}
-------------------------------------
It works fine when the string has Proj and SubProj but, when I
uncomment the later definition of string, I get MyAccount as my
project. Is there a way I can choose Project to $2 or $3 based on the
string?
Or, maybe I'm thinking of a wrong solution.
Could anyone give me some pointers on how to "get just the proj portion
when subproj is absent" from regex.( I dont really want to use splits
and substr.)
Thanks for your time,
Prabh
I wonder if this can be done through regex matching.
I have a string of unix path, which can be either
/home/MyAccount/Proj/SubProj or
/home/MyAccount/Proj
1. the "Proj" and "SubProj" portion, when the string has a SubProjFrom this I want to find
2. Just the "Proj" protion if there are no SubProjs.
I tried,
-------------------------------------
#!/usr/local/bin/perl -w
use strict ;
my $string = '/home/MyAccount/Proj/SubProj' ;
# my $string = '/home/MyAccount/Proj' ;
if ( $string =~ m/(.*)\/(.*)\/(.*)$/ )
{
print "Project: $2 \t SubProject: $3\n" ;
}
-------------------------------------
It works fine when the string has Proj and SubProj but, when I
uncomment the later definition of string, I get MyAccount as my
project. Is there a way I can choose Project to $2 or $3 based on the
string?
Or, maybe I'm thinking of a wrong solution.
Could anyone give me some pointers on how to "get just the proj portion
when subproj is absent" from regex.( I dont really want to use splits
and substr.)
Thanks for your time,
Prabh