in reply to Matching a string that you do not have any really good information about
You do have some information. It would appear that you have four different locations a path could be present in. The following code uses that knowledge to pull out the user name from the proper location.
# Offsets into the path my %indexes = (home => 1, Users => 2, Home => 1, export => 2); # This would be one of the scalars you have access to (I'm using the # CGI-BIN one in this code.) my $path = '/home/username/public_html/cgi-bin/dir'; # Remove the leading / and then split up my @pieces = split('/', substr($path, 1)); # Extract the user name information my $username = $pieces[$indexes{$pieces[0]}]; print "$username\n";
The %indexes variable holds the first part of the path as the key, and then the zero-based offset where the user name is stored after the path has been split.
|
|---|