perl : Remove empty lines from an array

Using grep the empty lines can be removed from an array in perl. Here is how.

### Remove any empty lines
@dataArray = grep(/S/, @dataArray);


S does the pattern matching that if everything on that line is a space.

 

  • Seth Williams

    You need the backslash before the ‘S’ like this: /S/

    • kunwarvjain

      Thank you Seth, I have corrected.