假设我有一个包含以下数据的数组:
@array[0] = "hello this is a text"
@array[1] = "this is a cat"
@array[2] = "this is a dog"
@array[3] = "this is a person"
@array[4] = "this is a computer"
@array[5] = "this is a code"
@array[6] = "this is an array"
@array[7] = "this is an element"
@array[8] = "this is a number"
我希望有一个循环,遍历所有数组元素并查找其中是否有值为"dog"的元素。如果存在"dog",则删除该元素。最终结果如下:
@array[0] = "hello this is a text"
@array[1] = "this is a cat"
@array[2] = "this is a person"
@array[3] = "this is a computer"
@array[4] = "this is a code"
@array[5] = "this is an array"
@array[6] = "this is an element"
@array[7] = "this is a number"
@var[index] = ...
的风格不佳。请使用$var[index] = ...
。这个表达式使用了$
符号,但仍然引用了命名数组@var
。请参见perldata
。 - mob