Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

get the 1st alphabet

Posted on 1999-07-07
5
Medium Priority
?
194 Views
Last Modified: 2010-03-04
Hi ! I have a file here :

open(FILE, "file.dat");
@data = <FILE>;
close(FILE);
foreach $bit (@data) {
($one, $two, $three, $four) = split(/\:/, $bit);
## May i noe how to get the 1st alphabet of $four ?
#for eg , $four is "my name is ....." n i want to get the 1st alphabet "m"

thanx very much.
0
Comment
Question by:prinx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 150 total points
ID: 1213916
You can say:

$four =~ /(\w)*/;
$first_letter = $1;

OR

(@letters) = unpack("C*",$four); # array of letters
$first_letter = $letters[0];
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1213917
#or

$first_letter = substr($four, 0, 1);
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213918
#for eg , $four is "+_8ßàáâãäåæçèéêëìíîïðñòóôõöùúûüýþÿmy name is", what would you want to get?
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 1213919
ozo, would this take care of the unprintables?

$four =~ /(\W*)?(\w)*/;
$first_letter = $2;



0
 
LVL 84

Expert Comment

by:ozo
ID: 1213920
($first_letter) = /(\w)/;
#would suffice if _0123456789 are considered letters.

$four is "my name is .....";
four =~ /(\W*)?(\w)*/;
$first_letter = $2;
#would get $first_letter='y';
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question