Jul 20, 2008

Using The / As A Delimiter In The Split Function - using the / as a Delimiter in the split function

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Perl Programming

free web hosting

Using The / As A Delimiter In The Split Function - using the / as a Delimiter in the split function

buckroe2
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.

Reply

jlhaslip
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);

Reply

mathmate
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

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. "delimiters in php" list - 33.85 hr back. (1)
Similar Topics

Keywords : , delimiter, split, function, delimiter, split, function

  1. Php Function To Format Url
    i did a php function to format url but it does not work help (0)


      Looking for , delimiter, split, function, delimiter, split, function

Searching Video's for , delimiter, split, function, delimiter, split, function
advertisement



Using The / As A Delimiter In The Split Function - using the / as a Delimiter in the split function



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE