Forum Discussion
Opher_Shachar_6
Feb 26, 2012Nimbostratus
Looking for a terse expression to get the (base) name of a Virtual
Hello all,
Given that [virtual name] evaluates to "/Common/Lishka.app/Company_vip"
What is the most terse expression to split that into
"/Common/Lishka.app/" and "Company_vip"
...
hoolio
Feb 29, 2012Cirrostratus
Hi Opher,
Out of curiosity, why do you want to get just the virtual name?
I think what you have is about as efficient as it would get if the folders could be more or less than two deep. If it's always two, you could use scan:
scan {/Common/Lishka.app/Company_vip} {/%[^/]/%[^/]/%[^/]} a b vs
set folder "/$a/$b/"
log local0. "\$folder: $folder, \$vs: $vs"
Or you could use a single regexp for any number of directories:
regexp -all {(/.*/)(.*)} {/Common/Lishka.app/Company_vip} all folder vsname
regexp -all {(/.*/)(.*)} {/Common/test/Lishka.app/Company_vip} all folder vsname
But the scan is ~3x faster than the regex:
% time {scan {/Common/Lishka.app/Company_vip} {/%[^/]/%[^/]/%[^/]} a b c; set folder /$a/$b/} 100
3 microseconds per iteration
% time {regexp -all {(/.*/)(.*)} {/Common/Lishka.app/Company_vip} all folder vsname} 100
10 microseconds per iteration
time {set vname "[string range "/Common/Lishka.app/Company_vip" [expr [string last / "/Common/Lishka.app/Company_vip"]+1] end]"} 100
6 microseconds per iteration
You could open a case with F5 Support to request an enhancement. Maybe we could add a -name and -folder flags or something like that to [virtual name] to get the name and folder.
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects