469,354 Members | 2,046 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to get the first word from a given string...

parajaganesh
How to get the first word from a given string in perl...
Oct 12 '07 #1
4 10526
KevinADC
4,059 Expert 2GB
The best way to get help on this forum with your questions is to post the code you have written so far to try and accomplish whatever it is you are doing. Posting a requirement with no code makes it seem like you are too lazy or unwilling to even try it yourself first, epecially when the question is such an easy one.

Beginning Perl
Oct 12 '07 #2
How to get the first word from a given string in perl...
Try this code, and modify as u required. i think this will enough for ur doubt.

$a="flintstones husband fred pal barney wife wilma pet dino";
if ($a) {
$a=~/^(.*?)\s/;
print $1;
}
Oct 13 '07 #3
KevinADC
4,059 Expert 2GB
Try this code, and modify as u required. i think this will enough for ur doubt.

$a="flintstones husband fred pal barney wife wilma pet dino";
if ($a) {
$a=~/^(.*?)\s/;
print $1;
}
We prefer that people show some effort before doing their code/work for them.
Oct 13 '07 #4
I would split each word using the space between each word as he splitter. Then I would place the shift of the new array into a scaler.
Oct 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by hagai26 | last post: by
2 posts views Thread by shapper | last post: by
2 posts views Thread by Kelly B | last post: by
reply views Thread by wildman | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.