LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2008, 07:12 AM   #1
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Rep: Reputation: 0
Post "perl help"


Hi all,
How to select the first word from a scalar variable.

ex: $a = "Hi all"
 
Old 02-04-2008, 07:59 AM   #2
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 510

Rep: Reputation: 53
There's a million solutions to this problem, depending on what you're going to do afterwards - you may use split for example and put all words into an array or use a reg ex and just grab the first word ..

@allwords = split(' ', $yourscalar); <-- split at spaces
print $allwords[0]; <-- just the first word

($firstword) = ($yourscalar =~ m/(\w+)/); <-- match first word, capture it and put it into $firstword


Something like this...
 
Old 02-05-2008, 03:54 AM   #3
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks all i got the answer.....
 
Old 02-05-2008, 03:55 AM   #4
sharath.bv
LQ Newbie
 
Registered: Jan 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks all i got the answer.....
 
Old 02-05-2008, 06:05 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,636
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
The mantra in Perl-land is "TMTOWTDI" = There's More Than One Way To Do It.

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
perl install error: Can't locate object method "new" via package "Module::Build::Vers powah Linux - Software 0 10-24-2006 01:57 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
Compiling KDE 3.2.0 - "Can't open perl script "/dcopidlng/kalyptus" linuxgamer09483 Linux - Software 3 04-09-2004 08:25 PM
LFS 4.1: Stalled at Perl, "missing seperator" error from "make" SparceMatrix Linux From Scratch 1 06-07-2003 03:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration