Wie kann ich ein Array filtern, ohne eine Schleife in Perl zu verwenden?

Hier versuche ich nur die Elemente zu filtern, die keinen Teilstring habenworld und speichern Sie die Ergebnisse im selben Array. Was ist der richtige Weg, um dies in Perl zu tun?

$ cat test.pl
use strict;
use warnings;

my @arr = ('hello 1', 'hello 2', 'hello 3', 'world1', 'hello 4', 'world2');

print "@arr\n";
@arr =~ v/world/;
print "@arr\n";

$ perl test.pl
Applying pattern match (m//) to @array will act on scalar(@array) at
test.pl line 7.
Applying pattern match (m//) to @array will act on scalar(@array) at
test.pl line 7.
syntax error at test.pl line 7, near "/;"
Execution of test.pl aborted due to compilation errors.
$

Ich möchte das Array als Argument an ein Unterprogramm übergeben.

Ich weiß, ein Weg wäre zu so etwas wie diesem

$ cat test.pl 
use strict;
use warnings;

my @arr = ('hello 1', 'hello 2', 'hello 3', 'world1', 'hello 4', 'world2');
my @arrf;

print "@arr\n";

foreach(@arr) {
    unless ($_ =~ /world/i) {
       push (@arrf, $_); 
    }
}
print "@arrf\n";

$ perl test.pl
hello 1 hello 2 hello 3 world1 hello 4 world2
hello 1 hello 2 hello 3 hello 4
$

Ich möchte wissen, ob es eine Möglichkeit gibt, dies ohne die Schleife zu tun (mithilfe einer einfachen Filterung).

Antworten auf die Frage(8)

Ihre Antwort auf die Frage