technojosh has asked for the wisdom of the Perl Monks concerning the following question:
I have a sub I use to build a name of a "test case" during an automation run. This name is a string that includes the directory of the Perl .pl file, as well as the file name with the suffix (.pl) stripped off.
So a file with the path 'C:\Tools\scripts\Test\Foo.pl' would produce the string 'Test - Foo'
here is my current sub, which works for me as long as there is no directory between 'Test' and 'Foo':
sub ScriptName { my ($self) = @_; my $name = Win32::GetFullPathName($0); my $dirChop = substr( $name, index($name,'\\scripts\\')+9 ); my $dir = substr( $dirChop, 0, index($dirChop,'\\') ); my $clean = substr( $name, rindex($name,'\\')+1, rindex($name,'.')-(rindex($name,'\\')+1) ); return "$dir - $clean" }
This will totally ignore the sub-directory in the path 'C:\Tools\scripts\Test\Unstable\Foo.pl', where I would like it to return the string 'Test - Unstable - Foo'... but I am no regex pro.
I am looking for a couple pointers:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need to capture an optional sub-directory name
by BrowserUk (Patriarch) on Mar 29, 2012 at 15:28 UTC | |
|
Re: Need to capture an optional sub-directory name
by spazm (Monk) on Mar 29, 2012 at 16:26 UTC | |
|
Re: Need to capture an optional sub-directory name
by AnomalousMonk (Archbishop) on Mar 29, 2012 at 18:35 UTC |