Splitting a line with multiple spaces with perl?

I am trying to split a line with multiple spaces. I just want to separate where there are 2 or more white spaces. I tried several things and I continue to get the same result, which is that it breaks after each letter. Here is the last thing I tried

@cellMessage = split(s/ {2,}//g, $message);
                foreach(@cellMessage){
                    print "$_ \n";
                }
+5
source share
5 answers
@cellMessage = split(/ {2,}/, $message);
+12
source

Keeping the syntax that you used in your example, I would recommend the following:

@cellMessage = split(/\s{2,}/, $message);
                foreach(@cellMessage){
                    print "$_ \n";
                }

(, ..). , split , //, $message .

+9
use strict;
use warnings;
use Data::Dumper;

#                  1    22     333
my $message = 'this that  other   555';
my @cellMessage = split /\s{2,}/, $message;
print Dumper(\@cellMessage);

__END__

$VAR1 = [
          'this that',
          'other',
          '555'
        ];
+2

:

@cellMessage = split (/\ s +/, $message);

, "@cellMessage = split (/{2,}/, $message); imo.

0

: \b(\s{2,})\b

- .

-1

All Articles