T
Tony
Howdy,
Here's my problem, I am reading in a file which contains lines of
different lengths. I need to set the last word on lines which match a
pattern (contain 'dogs') as the value of another variable.
# My file contains some lines that do not have the word
# dogs in them; and I am only interested here in lines
# that contain the word "dogs"
$START="dogs are:";
# I have opened my file, and now each instance of $_
# represents an entire line in sequence.
# So long as there is a line - repeat this loop.
while( $_=<FILE> ) {
$CURRENT_LINE=$_;
$CURRENT_LINE_DUPE=$CURRENT_LINE;
# Above I have setup two variables to hold the value
# of the current line.
#
# If and only if the current line contains the phrase "dogs Are:"
# do I continue to work on this line.
if ($CURRENT_LINE = /$START/) {
# What I want to do next is set the variable DOGSARE to the
# last word in this line.
$DOGSARE=~ m|(\w$)|;
print "$RDOGSARE";
}
}
In short - this doesn't work. The problem is setting the DOGSARE
variable value; I cannot seem to get it to set.
Any help would be greatly appreciated.
Thanks in advance,
TC
Here's my problem, I am reading in a file which contains lines of
different lengths. I need to set the last word on lines which match a
pattern (contain 'dogs') as the value of another variable.
# My file contains some lines that do not have the word
# dogs in them; and I am only interested here in lines
# that contain the word "dogs"
$START="dogs are:";
# I have opened my file, and now each instance of $_
# represents an entire line in sequence.
# So long as there is a line - repeat this loop.
while( $_=<FILE> ) {
$CURRENT_LINE=$_;
$CURRENT_LINE_DUPE=$CURRENT_LINE;
# Above I have setup two variables to hold the value
# of the current line.
#
# If and only if the current line contains the phrase "dogs Are:"
# do I continue to work on this line.
if ($CURRENT_LINE = /$START/) {
# What I want to do next is set the variable DOGSARE to the
# last word in this line.
$DOGSARE=~ m|(\w$)|;
print "$RDOGSARE";
}
}
In short - this doesn't work. The problem is setting the DOGSARE
variable value; I cannot seem to get it to set.
Any help would be greatly appreciated.
Thanks in advance,
TC