Trying to extract the last number on a line, with sets of numbers delimited by spaces
So I've extracted the digits from a log file and it looks like this:
2011 04 13 23 54 14 601 04 13 23 54 14 10 35 1 14 8080 59 250
What I'm trying to get is the last number (250), and it will loop thro开发者_开发问答ugh each line of the log. Once I get the last number from each line, I will do some calculations...I just can't extract that last number at the end of the line. Thanks!
while (<>) {
my ($last) = /(\d+)$/;
}
If your data is an array, @digits
, then the last one is $digits[-1]
.
If your data is in a string, use the split
to get it into an array.
精彩评论