Using a period as a delimiter in the split() function 
Author Message
 Using a period as a delimiter in the split() function

Hi people,

I am currently having a problem with using a period as a delimiter in the
split function. I am attempting to separate segments of a domain name into
elements of an array, using the period(s) in the domain name as the
delimiter. The offending line of code is as follows:

At the moment a null value is passed to the array. If any of you have any
suggestions for a way to get around this I would be very grateful.

TIA,
Gareth



Wed, 06 Mar 2002 03:00:00 GMT  
 Using a period as a delimiter in the split() function

Quote:

> Hi people,

> I am currently having a problem with using a period as a delimiter in the
> split function. I am attempting to separate segments of a domain name into
> elements of an array, using the period(s) in the domain name as the
> delimiter. The offending line of code is as follows:



Gareth, the first argument to split is treated as a regular expression.
A . is a regular expression metacharacter, and thus must be quoted if
it is to be considered a literal period.  Try:

Quote:

> At the moment a null value is passed to the array. If any of you have any
> suggestions for a way to get around this I would be very grateful.

> TIA,
> Gareth

--
Bob Walton


Wed, 06 Mar 2002 03:00:00 GMT  
 Using a period as a delimiter in the split() function
[Posted and a courtesy copy sent.]



Quote:
> I am currently having a problem with using a period as a delimiter in the
> split function. I am attempting to separate segments of a domain name into
> elements of an array, using the period(s) in the domain name as the
> delimiter. The offending line of code is as follows:


> At the moment a null value is passed to the array. If any of you have any
> suggestions for a way to get around this I would be very grateful.

Yes.  Instead of writing the argument for split() as a string, write it
as what it really is, a regex.  Then you will see that '.' is a regex
metacharacter, which needs to be escaped to have its literal meaning.


--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Wed, 06 Mar 2002 03:00:00 GMT  
 Using a period as a delimiter in the split() function
Thanks for all the help on this one guys, much appreciated!

Gareth



Thu, 07 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

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

2. Using SPLIT function with a Period

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

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

5. Using Different Delimiters in Split

6. time period splitting

7. using split function twice on same line

8. splitting with embedded delimiters

9. SPLIT Problem - Embedded Delimiter

10. splitting but maintaining delimiter?

11. returning split() delimiters...

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

 

 
Powered by phpBB® Forum Software