On Tue, 14 May 2002, Johannes Studt wrote:

     > I wrote:
     >
     > $str = '\\server\path';
     > (undef, $server, $path) = split (/\\/, $str);
     > print 'Server=', $server, ' Path=', $path;
     >
     > Peter Vogel wrote:
     >
     > >That only works in the "path" part doesn't contain "\".
     > >For example, this is a valid UNC path:
     > >\\server\share\subdir1\subsubdir1
     > >Your suggestion would only get server and share.
     >
     > Yes, you're right, but if I extend the split with an
     > optional argument like this, it should work...
     >
     > $str = '\\server\share\dir\subdir\file.ext';
     > (undef, $server, $path) = split (/\\/, $str, 3);
     > print 'Server=', $server, ' Path=', $path;
     >
     > Johannes Studt

I was thinking what if the UNC path had more subdirs... here it goes:

C:\>perl -e
"$line="\\\\server\\share\\dir\\subdir\\otherdir";($server=$line)=~s/^(\\\\\w*).*$/$1/e;print
"$server\n";"
\\server

C:\>

rgrds,
m4c.

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to