473,392 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,392 software developers and data experts.

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 42631
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,509 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lkrubner | last post by:
Last year I asked a bunch of questions about character encoding on this newsgroup. All the answers came down to using ord() in creative ways to try to make guesses about multi-byte characters. I...
1
by: flam | last post by:
Hello, I am having a hard time spliting a string into an array for use in a search. Here is the situation. The user will input a search string. Normally I can just split the string by "split...
0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
4
by: Gangreen | last post by:
Hi, I'm new to Perl but I have some experience in other languages. Anyway I need to split a string on the character "|". let's say our string is "one|two|three" when I try the following code:...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.