How to store the output of a command in an array line by line in perl?

时间:2016-09-01 06:26:06

标签: perl

For eg, I want to store the contents of the command ipconfig in an array, such that each line of output is stored in a new index of array, i.e. array[0] contains the 1st line output. array[1] contains the 2nd line output and so on.

How can I achieve that?

1 个答案:

答案 0 :(得分:9)

一个简单的

@array = `ipconfig`;

诀窍。请注意,正如Borodin正确指出的那样,所分配的数组元素包括换行符。