Remove whitespace before text in Perl

Home > Search
  by

Let's say you have an array named @greeting, and when the array is printed, there is random whitespace to the left of the text.

   Hello
  World
       Hello
    World

 

The map function can be used to eliminate white space to the left of text, so that all of the text is left justified.

map { s/^\s+// } @greeting;

 

The result will be:

Hello
World
Hello
World

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments