Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have just started to learn Perl and i'm working on some string manipulation and pattern matching.
I would like to know how to return a word that is next to a word i am specifying.
for example, in the following string, i would like to return the word 'red' when i search for 'color: '.
| shape: square | color: red | size: 320x320 | id: 0001
I am reading in a file into an array and am looking at each line. Each line is different, in that it could be just text or whitespace (the line i am actually reading is at the footer of the first page). Here is the code i have so far...
use strict; my @file = <STDIN>; my $word = "color: "; for my $lineno ( 0 .. $#file ) { if ($file[$lineno] =~ /\b$word\b/){ } }
Thank you for your help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: return a word next to the word you give
by liz (Monsignor) on Oct 16, 2003 at 12:19 UTC | |
by Abigail-II (Bishop) on Oct 16, 2003 at 12:32 UTC | |
by liz (Monsignor) on Oct 16, 2003 at 13:31 UTC | |
|
Re: return a word next to the word you give
by Abigail-II (Bishop) on Oct 16, 2003 at 12:17 UTC | |
|
Re: return a word next to the word you give
by Roger (Parson) on Oct 16, 2003 at 12:26 UTC | |
|
Re: return a word next to the word you give
by greenFox (Vicar) on Oct 16, 2003 at 15:14 UTC |