Perl: find a word in a line that precedes :

ambuli
ambuli used Ask the Experts™
on
Hi there,

If a line is in the form:

something here IDLE_THREAD: time in 23.2 s

I want to find out the word IDLE_THREAD
Thanks,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
my $line = "something here IDLE_THREAD: time in 23.2 s";
my ($match) = $line =~ m/\s*([A-Z_]+):/;
ozo
Most Valuable Expert 2014
Top Expert 2015
Commented:
$_='something here IDLE_THREAD: time in 23.2 s';
($word)=/(\w+):/;
my ($name) = $string =~ m{(\w+):};

Or if there could potentially be more than one colon:

my ($name) = $string =~ m{(\w+):\s+time\s+in};
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
the \s* makes no difference at all to the results of $line =~ m/\s*([A-Z_]+):/

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial