in reply to Re: parse a string
in thread parse a string
First, you split on a comma, but since there is whitespace involved, i chose to use a regex that says "zero or more whitespace followed by a literal comma followed by zero or more whitespace". Since split returns a list, you can take advantage and add an index on the spot without using a temporary variable (well, sort of). In this case the index is -1, which is the last element.my $string = "something, something, something, this"; my $lastword = ( split(/\s*,\s*/, $string) )[-1];
Of coures, this is not an efficient way to do it, but ... TIMTOWTDI! ;)
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|