471,825 Members | 869 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 10952
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

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.