in reply to read a word from a line
To print out only part of the line, you need to use a capturing regular expression. You will also need to escape the ( and ) because those have special meaning in a regular expression. So to get the stuff between the parenthesis after pond:
print $1 if (/pond\(([^)]*)\)/);
[^)]* means match everything up until the first closing ). ([^)]*) says to capture it and store it in $1. \( and \) say "treat ( and ) as normal parenthesis". See perlretut for more information.
Best, beth
Update:Fixed typo, as per AnomalousMonk below. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: read a word from a line
by AnomalousMonk (Archbishop) on Feb 25, 2009 at 15:31 UTC | |
|
Re^2: read a word from a line
by sharan (Acolyte) on Feb 25, 2009 at 17:11 UTC | |
by ELISHEVA (Prior) on Feb 25, 2009 at 18:24 UTC |