Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: A Better Way to Find the Position of the Last Non-Whitespace Character in the Last Element of an Array.

by kyle (Abbot)
on Apr 22, 2009 at 17:06 UTC ( #759345=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: A Better Way to Find the Position of the Last Non-Whitespace Character in the Last Element of an Array.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2014-12-22 14:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls