How to use split function to split on a backslash 
Author Message
 How to use split function to split on a backslash

I am trying to split a string which contains a backslash.

I have tried:

nothing seems to work I get errors from "search pattern not terminated" to
"syntax error".

$string contains something like "domainName\userName"

and I would like to end up with:
$words[0] = "domainName"
$words[1] = "userName"

Any Ideas?

Thanks in advance.



Tue, 04 Oct 2005 22:37:07 GMT  
 How to use split function to split on a backslash

Quote:
>> On Fri, 18 Apr 2003 15:37:07 -0600,

> I am trying to split a string which contains a
> backslash.  I have tried:


> '\\', $string;

The first argument to split() is a regular expression.

Quote:
> $string contains something like "domainName\userName"
> and I would like to end up with: $words[0] =
> "domainName" $words[1] = "userName"

    my $string = 'domainName\userName';

    my ($domain, $user) = split /\\/, $string;

hth
t



Tue, 04 Oct 2005 22:28:52 GMT  
 How to use split function to split on a backslash
Bingo!!

thanks a bunch...


Quote:
> >> On Fri, 18 Apr 2003 15:37:07 -0600,

> > I am trying to split a string which contains a
> > backslash.  I have tried:



> > '\\', $string;

> The first argument to split() is a regular expression.

> > $string contains something like "domainName\userName"
> > and I would like to end up with: $words[0] =
> > "domainName" $words[1] = "userName"

>     my $string = 'domainName\userName';

>     my ($domain, $user) = split /\\/, $string;

> hth
> t



Tue, 04 Oct 2005 22:45:48 GMT  
 How to use split function to split on a backslash

Quote:

> I am trying to split a string which contains a backslash.

> I have tried:





> nothing seems to work I get errors from "search pattern not terminated" to
> "syntax error".

> $string contains something like "domainName\userName"

> and I would like to end up with:
> $words[0] = "domainName"
> $words[1] = "userName"

use strict;
use warnings;
use diagnostics;

my $string = 'How\about\matching\it\the\correct\way\?';


HTH,

Jodyman



Wed, 05 Oct 2005 00:07:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. PERLFUNC: split - split up a string using a regexp delimiter

2. Using split to return a @ without splitting on spaces

3. PERLFUNC: split - split up a string using a regexp delimiter

4. using split function twice on same line

5. Using SPLIT function with a Period

6. Using a period as a delimiter in the split() function

7. perlcc does not compile when split to array function is used

8. Using a period as a delimiter in the split() function

9. how to split backslash

10. Problem with join function (and split function)

11. split inside split - can it be done ?

12. Help with split please - or maybe split isn't correct

 

 
Powered by phpBB® Forum Software