|
|
|
|
![]() ![]() |
Feb 25 2007, 10:09 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 1 Joined: 25-February 07 Member No.: 39,208 |
How do I use the / as a Delimiter in the split function?
This is the code now: CODE ($url1, $url2, $url3) = split (/\./,$Image_Upload_4); This is what I want to be able to split up the url: CODE ($url1, $url2, $url3) = split (/\/./,$Image_Upload_4); I have tried to put the / in quotes but that did'nt work. Thanks for any help. |
|
|
|
Feb 25 2007, 10:41 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,882 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
The split function uses Regex, so the correct method is based on the regex use of square brackets.
See here Second example is better than the first. I am thinking the correct code for what you want to do would be something like this : CODE ($url1, $url2, $url3) = split ([/\/./],$Image_Upload_4);
|
|
|
|
Mar 4 2007, 04:25 PM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 7 Joined: 3-March 07 Member No.: 39,519 |
As buckroe2 mentioned, the split character you supply is a regular expression, which can be translated into one single
character or many characters. In your particular case, many different versions would work, as long as it translates into the single character /. Here is a base test script you can use: CODE $line="http://www.abc.com/HTTP://www.def.com"; @array=split "/", $line; foreach $i (@array){ printf("%s\n",$i);} which gives as results: CODE http: www.abc.com HTTP: www.def.com Tool completed successfully The empty lines represent a null field caused by the double slashes // . The following expressions all translate to a single /: "/", '/', '[/]'. In a regular expression, single quotes will cause an interpretation 'as-is' without further translation. Brackets [] will enclose alternative characters, and contents of "" will be further translated according to regular expression rules. Perl.org has an excellent tutorial on regular expressions that explains everything about it: http://perldoc.perl.org/perlretut.html |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 27th July 2008 - 01:20 AM |