Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse a URL-like string...need help

Status
Not open for further replies.

tapodaca

MIS
Dec 17, 2003
12
US
Ok, here is what I am looking for:

I have an $ENV{VARIABLE} that looks like this:
C:\Data\IBM\wsad\workspace\my_workspace_project\MCMNET\MCMNET\another directory\JSP\file_name.jsp
***Take note that the file structure and their file names could have spaces.

Now, I have tried several times to just get a certain section of this URL parsed out. I have tried split(), pop(), shift()...but I just can't quite get it right.

What I need is to get the \MCMNET\MCMNET\anotherdirectory\JSP\ out. Even if the file_name.jsp had to stay that would be fine. Does anyone have any ideas or tips?

Go Tech!
 
Oh, and that is not always going to be a static path!

C:\Data\IBM\wsad\workspace\my_workspace_project\ could change depending on the users preferences...so you I can't just "know" what to take out. Also, the rest may change depending on our Java development paths too...so none of this "path" is static.

Go Tech!
 
Another thing...I can get the first part I am trying to delete (or take out) in another $ENV{VARIABLE}:

$cc_pn = $ENV{CLEARCASE_PN}; --> gives me the entire path:
***C:\Data\IBM\wsad\workspace\my_workspace_project\MCMNET\MCMNET\another directory\JSP\file_name.jsp

$cc_sn_pn = $ENV{CLEARCASE_SNAPSHOT_PN}; --> gives me the portion of the path I want removed (minus the file name (file_name.jps), but I can then utilize code I already have that gives me just the file name..:
***C:\Data\IBM\wsad\workspace\my_workspace_project
Go Tech!
 
Here is a little sample code I put together that does what you want:

$a1 = "x o f z r";
$a2 = "x o f";
$dup = 0;

@x1 = split(/ /,$a1);
@x2 = split(/ /,$a2);

foreach $c1 (@x1) {
foreach $c2 (@x2) {
if ($c1 eq $c2) {
$dup = 1;
}
}
if ($dup == 0) {
$new = $new.$c1;
$new = $new." ";
}
$dup = 0;
}


do a split on \ and build your new string.



Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
Thanks for your input! It gave me more ideas and I came up with this:

$cc_pn = $ENV{CLEARCASE_PN};
$cc_snapshot_pn = $ENV{CLEARCASE_SNAPSHOT_PN};

$spn_len = length($cc_snapshot_pn);
$new_path = substr($cc_pn,$spn_len);

@path_array = split(/\\/, $new_path);
pop(@path_array);

$path = join("\\", @path_array);

Again, that's for the help.

Go Tech!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top