vboy1997 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I have a couple of grep statements that currently only output all files on 1 single line like file1.txtfile2.txtfile3.txt. I would like to have them output on separate lines like,

file1.txt
file2.txt

print grep {(stat)3 > 1} @things;

print grep {-l readlink} @syms;

I've tried many ways already but no luck. Please help me or show me the correct way to do this. Thank you all in advanced.

Replies are listed 'Best First'.
Re: Grep result in separate lines
by kennethk (Abbot) on May 09, 2011 at 16:08 UTC
    The clearest way to do it would be in insert a join into your expression:

    print join "\n", grep {(stat)3 > 1} @things;

    If you wanted to be clever, you can set the value of the output field separater using the special variable $,:

    local $, = "\n"; print grep {(stat)3 > 1} @things;

    Beware creating cleverness and long compound statements, as they can make maintenance more difficult than it needs to be.

Re: Grep result in separate lines
by JavaFan (Canon) on May 09, 2011 at 16:06 UTC