Mojo::DOM and Text Method to remove spaces

145 views Asked by At

I have the following code which using Mojo::DOM to get the text

my $text =ua->get('https://my_site.org'.$_)->res->dom->at('div.container-fluid h1')->text;

while the text under h1 if on the following format :

<h1>
                       my_text                    </h1>

the $text is come with the heading and trailing spaces

I can do something like this to remove the heading and the trailing spaces

  $text =~ s/^\s+//;
  $text=~ s/\s+$//;

but I am wondering if its possible to do this with mojolicious functionality ?

1

There are 1 answers

0
Jim Davis On BEST ANSWER

Mojo::Util provides trim which should do what you want:

my $trimmed = trim $str;

Trim whitespace characters from both ends of string.