LoginSignup
15
12

More than 5 years have passed since last update.

配列から指定した内容の要素を削除する

Last updated at Posted at 2014-03-18

何番目の要素を削除とかはよくあるけど、指定した内容の要素を削除というサンプルがなかったので簡単だけど書いてみる。

use strict;
use warnings;

my @lst = qw( foo bar baz );
print "@lst\n";
# foo bar baz

@lst = grep $_ ne "bar", @lst;
print "@lst\n";
# foo baz 

grep関数で正にならないものを返すだけだが、別にgrepの引数は正規表現でなくていいことを以外とみんな知らない。

15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12