Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

string to character array in PERL

Question posted by: bhanumathy (Newbie) on November 15th, 2006 05:06 PM
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.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Studentmadhura05's Avatar
Studentmadhura05
Newbie
25 Posts
November 15th, 2006
05:30 PM
#2

Re: string to character array in PERL
I am also having the same problem. Let me know if you find a solution!
Thanks

Reply
GunnarH's Avatar
GunnarH
Member
83 Posts
November 15th, 2006
08:07 PM
#3

Re: string to character array in PERL
Quote:
Originally Posted by bhanumathy
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?

Reply
miller's Avatar
miller
Moderator
830 Posts
November 16th, 2006
01:39 AM
#4

Re: string to character array in PERL
GunnarH++

TFM: http://perldoc.perl.org/functions/split.html

Reply
GunnarH's Avatar
GunnarH
Member
83 Posts
November 16th, 2006
02:25 AM
#5

Re: string to character array in PERL
Quote:
Originally Posted by miller

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. :(

Reply
bhanumathy's Avatar
bhanumathy
Newbie
4 Posts
November 16th, 2006
05:49 AM
#6

Re: string to character array in PERL
Quote:
Originally Posted by Studentmadhura05
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

Reply
sharif's Avatar
sharif
Newbie
4 Posts
November 16th, 2006
06:51 AM
#7

Re: string to character array in PERL
Quote:
Originally Posted by bhanumathy
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.

Reply
miller's Avatar
miller
Moderator
830 Posts
November 16th, 2006
07:51 PM
#8

Re: string to character array in PERL
Quote:
Originally Posted by sharif
@chars=split(/(?=\w)/,$string);


Slightly overcomplicated there sharif. This works just as well, and is quite a bit easier to read, I think.

Code: ( text )
  1. @chars = split '', $string;


Again, they should just read the manual: http://perldoc.perl.org/functions/split.html

Reply
litening's Avatar
litening
Newbie
1 Posts
July 3rd, 2008
08:08 PM
#9

Re: string to character array in PERL
"spoon feeded".
I think it's time for you to RTF Dictionary!!

litenin

Quote:
Originally Posted by GunnarH
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. :(

Reply
numberwhun's Avatar
numberwhun
Forum Leader
1,861 Posts
July 3rd, 2008
10:05 PM
#10

Re: string to character array in PERL
Quote:
Originally Posted by litening
"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

Reply
Phatfingers's Avatar
Phatfingers
Newbie
2 Posts
July 24th, 2008
11:47 PM
#11

Re: string to character array in PERL
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.

Quote:
Originally Posted by numberwhun
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

Reply
KevinADC's Avatar
KevinADC
Expert
3,068 Posts
July 25th, 2008
12:11 AM
#12

Re: string to character array in PERL
lock this thread already.

Reply
Closed Thread
Not the answer you were looking for? Post your question . . .
184,210 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Perl Forum Contributors