Solved

Perl: Remove last non-white space character from string (most elegant solution?)

Posted on 2011-09-13
1
348 Views
Last Modified: 2012-05-12
What is the most concise way to remove the last non-white space character from a string?
0
Comment
Question by:ZuZuPetals
1 Comment
 
LVL 9

Accepted Solution

by:
parparov earned 500 total points
ID: 36531732
$string =~ s/\S(\s*)$/$1/ if you need to retain the whitespace at the end
$string =~ s/\S\s*$// if you don't need to retain the whitespace at the end
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Script to append xml file 32 184
perl CPAN issue 3 90
Perl Application JSON Receiving Strange Java Error 3 65
create a gui in perl 3 42
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now