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: Beginner:
string to array?

 



Vincent Jansen
Deleted

May 4, 2000, 11:59 AM

Post #1 of 5 (748 views)
string to array? Can't Post

hi can anyone tell me how to put the data of a string like

$string="abc%def%ghi"

into an array like

@array="abc
def
ghi"

Thanks!


perlkid
stranger

May 4, 2000, 12:30 PM

Post #2 of 5 (748 views)
Re: string to array? [In reply to] Can't Post

 
To add to the left of the array use this,

unshift(@array, "$test");

and to add to the right of an array use this,

push(@array, "$test1");

perlkid


Vincent Jansen
Deleted

May 4, 2000, 12:57 PM

Post #3 of 5 (748 views)
Re: string to array? [In reply to] Can't Post

Thanks, but I think I was a little vague.
It comes down to this.

I got an unspecified amount of lines from a textinput in a form named $FORM{'comment'}.
This I wrote to a single line in a file, by stripping it from \n. (I replaced \n with %)

Now I want to read it again and make into something that reproduces the original input.

Hope you can help
Thanks


perlkid
stranger

May 4, 2000, 4:02 PM

Post #4 of 5 (748 views)
Re: string to array? [In reply to] Can't Post

 
I see,

Try using the s///g; method.

$theline =~ s/%/\\n/g;

If you are going to print it back to the page in html then use something closer to this.

$theline =~ s/%/<br>/g;

If you still want it in the array unshift it into the array and change $theline to $array[0] so you'll have

$array[0] =~ s/%/\\n/g;
or
$array[0] =~ s/%/<br>/g;

I hope I'm not way off again.

perlkid


Vincent Jansen
Deleted

May 5, 2000, 12:53 AM

Post #5 of 5 (748 views)
Re: string to array? [In reply to] Can't Post

In fact you're right on.
This works perfectly.

Thanks a lot!

 
 


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

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