1

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 ?

jsor
  • 97
  • 5

1 Answers1

1

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

my $trimmed = trim $str;

Trim whitespace characters from both ends of string.

Jim Davis
  • 5,241
  • 1
  • 26
  • 22