How to strip spaces out of a string in perl

→ Are you a new visitor? Please visit the page guidance for new visitors ←

How to strip spaces out of a string in perl

You have a variable string that may have blank spaces at the end of the string or at the start of the string and you need to remove these spaces so that you can make use properly of the value of that variable.

Scenario

Solution

Create a function which is more feasible to use across all your project:

Then just call the function wherever you need the spaces at the end or at the start of the string removed.

Output

This will only be working if you want to strip at the end or at the start of the string, you can of course break the function down and use only one side of them if you wish, but in most cases you want to make sure that you removedĀ  spaces in both sides.

Request an article ←