By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

string to character array in PERL

P: 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.
Nov 15 '06 #1
Share this Question
Share on Google+
11 Replies


P: 25
I am also having the same problem. Let me know if you find a solution!
Thanks
Nov 15 '06 #2

P: 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
Expert 100+
P: 1,089

P: 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

P: 4
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

P: 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
Expert 100+
P: 1,089
@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

P: 1
"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
Expert Mod 2.5K+
P: 3,503
"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

P: 2
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
Expert 2.5K+
P: 4,059
lock this thread already.
Jul 25 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.