CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Split Operation

 



santhosh_89
Novice

Jul 30, 2009, 8:45 PM

Post #1 of 7 (2359 views)
Split Operation Can't Post

I have a scalar variable, which needs to be split into an array.

Input :

my $test="[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p";


Output :

@array = ( [a, b], c, 'd', [e, [f, g, h, [i, j], k, l], m, n], o, p);


KevinR
Veteran


Jul 30, 2009, 8:55 PM

Post #2 of 7 (2356 views)
Re: [santhosh_89] Split Operation [In reply to] Can't Post


Code
my $test="[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p";  
@array = split(/,/,$test);
print "$_\n" for @array;

-------------------------------------------------


santhosh_89
Novice

Jul 30, 2009, 9:03 PM

Post #3 of 7 (2353 views)
Re: [KevinR] Split Operation [In reply to] Can't Post

Before seeing the output,don't put the answer,Please check the output.
Example the array will have the element [a,b] in first index.But you have split based on the comma(,).If you do like wise the first element will be '[a',.......


(This post was edited by santhosh_89 on Jul 30, 2009, 9:05 PM)


KevinR
Veteran


Jul 30, 2009, 9:08 PM

Post #4 of 7 (2351 views)
Re: [santhosh_89] Split Operation [In reply to] Can't Post

Your example output is so unclear no one will understand it. But I don't feel like trying to figure it out for you anyway.
-------------------------------------------------


(This post was edited by KevinR on Jul 30, 2009, 9:09 PM)


ichi
User

Jul 30, 2009, 9:41 PM

Post #5 of 7 (2346 views)
Re: [santhosh_89] Split Operation [In reply to] Can't Post


In Reply To
Before seeing the output,don't put the answer,Please check the output.
Example the array will have the element [a,b] in first index.But you have split based on the comma(,).If you do like wise the first element will be '[a',.......

kev is kind enough to help you, so be polite. you are the beggar here, so you can't choose.


Code
my $test="[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p";   
@s = split(/,/,$test);
print join(",",splice(@s,0,2)) ."\n" ;
print join("," ,@s);

the above is not complete. I expect you to get the gist of it, and complete it yourself.


santhosh_89
Novice

Jul 31, 2009, 1:11 AM

Post #6 of 7 (2343 views)
Re: [ichi] Split Operation [In reply to] Can't Post

I am not asking the answer from beggar.


ichi
User

Jul 31, 2009, 1:45 AM

Post #7 of 7 (2342 views)
Re: [santhosh_89] Split Operation [In reply to] Can't Post

you are the one requesting help, so you are the "beggar". when you ask for help, you say "please". that's basic courtesy. Also, YOU are the one who is supposed to check your output. What kev can give you is only guidance. the rest, is up to you to explore.


(This post was edited by ichi on Jul 31, 2009, 1:47 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives