BIG FAT WARNING: Read Unfortunately benchmarking things with $& isn't easy... to learn why this code is wrong, and the numbers it gives shouldn't be trusted
m// and capturing parentheses are your friend. Also, your code won't match all server names: if nothing else, spaces and digits are valid in SMB machinenames. And when the question is of speed, Benchmark is the answer. (My answer is below, under "theorbtwo=>".)
#!perl use warnings; use Benchmark; $unc = '\\server_name\sys_share'; $unc =~ s/^\W*\w+//; $server = $&; $server =~ s/^\W+//; Benchmark::timethese(100000, { blackadder => sub { $lunc = $unc; $lunc =~ s/^\W*\w+//; $server = $&; $server =~ s/^\W+//; }, theorbtwo => sub { $unc =~ m/^\\\\([^\\]+)\\/; $server=$1; } });
In reply to Re: Obtaining server name from UNC path
by theorbtwo
in thread Obtaining server name from UNC path
by blackadder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |