469,326 Members | 1,359 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

string to character array in PERL

hi, I am a beginer in PERL. got stuck in trying to figure out how strings are converted to character arrays.

for ex: I want to convert @str1=("apple") to a charcter array like
@chr1=('a','p','p','l','e')

can some one help me how to implement the above?
I basically need to get a string form the user and address each character(letter) of that string. well, iam in the middle of my assignment...so a quick reply from any one is appreciated.

regards,
bhanumathy.
Nov 15 '06 #1
11 42404
I am also having the same problem. Let me know if you find a solution!
Thanks
Nov 15 '06 #2
GunnarH
83
I want to convert @str1=("apple") to a charcter array like
@chr1=('a','p','p','l','e')

can some one help me how to implement the above?
A function for doing that was implemented in Perl a long time ago. Time to RTFM?
Nov 15 '06 #3
miller
1,089 Expert 1GB
GunnarH++

TFM: http://perldoc.perl.org/functions/split.html
Nov 16 '06 #4
GunnarH
83
TFM: http://perldoc.perl.org/functions/split.html
Yeah, that's indeed the function I was thinking of. ;)

My point is that being a beginner isn't an excuse for asking for help without first making a serious effort to find the answer by help of the docs. Browsing the perlfunc manpage for a suitable function should always be part of such an effort IMO. Now I had told him that there is an applicable function, which should have been enough of a pointer.

There are too many people nowadays who expect to be spoon feeded. :(
Nov 16 '06 #5
I am also having the same problem. Let me know if you find a solution!
Thanks
Hi,
check out this link.

http://perldoc.perl.org/functions/split.html
Nov 16 '06 #6
sharif
4
hi, I am a beginer in PERL. got stuck in trying to figure out how strings are converted to character arrays.

for ex: I want to convert @str1=("apple") to a charcter array like
@chr1=('a','p','p','l','e')

can some one help me how to implement the above?
I basically need to get a string form the user and address each character(letter) of that string. well, iam in the middle of my assignment...so a quick reply from any one is appreciated.

regards,
bhanumathy.
Hi ,

use the following code for ur problem

@chars=split(/(?=\w)/,$string);

Regards ,
sharif.
Nov 16 '06 #7
miller
1,089 Expert 1GB
@chars=split(/(?=\w)/,$string);
Slightly overcomplicated there sharif. This works just as well, and is quite a bit easier to read, I think.

Expand|Select|Wrap|Line Numbers
  1. @chars = split '', $string;
  2.  
Again, they should just read the manual: http://perldoc.perl.org/functions/split.html
Nov 16 '06 #8
"spoon feeded".
I think it's time for you to RTF Dictionary!!

litenin

Yeah, that's indeed the function I was thinking of. ;)

My point is that being a beginner isn't an excuse for asking for help without first making a serious effort to find the answer by help of the docs. Browsing the perlfunc manpage for a suitable function should always be part of such an effort IMO. Now I had told him that there is an applicable function, which should have been enough of a pointer.

There are too many people nowadays who expect to be spoon feeded. :(
Jul 3 '08 #9
numberwhun
3,503 Expert Mod 2GB
"spoon feeded".
I think it's time for you to RTF Dictionary!!

litenin
Litenin,

First, this is a place of learning. Being condescending as you were is not beneficial to those trying to learn something. Sometimes spoon feeding a person something is the way to get them to learn, sometimes it isn't. It all depends on the situation. Lets try to be a little more understanding of those who do not "know it all".

Also, seeing as how this thread is a year and a half old, I doubt that the original OP will be reading it. Besides, they have probably have learned this material already.

Regards,

Moderator
Jul 3 '08 #10
In Litenin's defense... it appears he was taking a poke at GunnarH for using the word "feeded" instead of "fed" in GunnarH's belittling of the requestor for asking for help too soon (hence, the "Dictionary" reference). Litenen was, in fact, defending the newbie, not attacking him.

Litenin,

First, this is a place of learning. Being condescending as you were is not beneficial to those trying to learn something. Sometimes spoon feeding a person something is the way to get them to learn, sometimes it isn't. It all depends on the situation. Lets try to be a little more understanding of those who do not "know it all".

Also, seeing as how this thread is a year and a half old, I doubt that the original OP will be reading it. Besides, they have probably have learned this material already.

Regards,

Moderator
Jul 24 '08 #11
KevinADC
4,059 Expert 2GB
lock this thread already.
Jul 25 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by flam | last post: by
16 posts views Thread by Don Starr | last post: by
20 posts views Thread by Opettaja | last post: by
14 posts views Thread by Shhnwz.a | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
4 posts views Thread by Gangreen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.