in reply to A Better Way to Find the Position of the Last Non-Whitespace Character in the Last Element of an Array.
You could easily eliminate a variable:
my @MessageLines = ( 'Message Line 1', 'Message Line 2', 'Message Line 3', 'Prompt: ' ); if ( $MessageLines[-1] =~ m{ \A ( .* \S ) \s* \z }xms ) { my $CursorCol = length $1; print "\$CursorCol\[$CursorCol\]\n"; }
If all you want is a one liner, this works:
my $CursorCol = grep { /\S/ .. undef } reverse split //, $MessageLines[-1];
I think what you have is easier to understand, however.
|
|---|