Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-09-13
1
352 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 99
how to exit a  for loop inside a function with return value in bash 5 103
perl: Cleaning meta tags using RegEX 12 82
Regex rule to match two different url 5 74
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

792 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