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

How would I print a line space between extracted lines. The results currently look like this used this code:
open FILE, <myfile .... etc. print grep /CALL|AUTHOR|TITLE/, <FILE> CALL # 123 AUTHOR JOE TITLE PERL --- need line break after title CALL 456 AUTHOR TERRY TITLE HELP
I'd like a line break between TITLE and call

Replies are listed 'Best First'.
Re: print spaces with grep
by Zaxo (Archbishop) on Jan 19, 2005 at 11:33 UTC

    Two of many ways to get the spaces, the first does the newline after the TITLE line, too.

    print map { chomp; $_ . /^TITLE/? "\n" : ' '; } grep { /$re/ } <FILE>;
    or
    { local $" = ' '; # just making sure - this is the default print "@{[grep {/$re/} <FILE>]}"; }
    The trinary (?:) operator in the first chooses space or newline depending on the first word.

    After Compline,
    Zaxo

Re: print spaces with grep
by holli (Abbot) on Jan 19, 2005 at 11:21 UTC
    print map { /^TITLE/ ? "$_\n" : $_ } grep { /^(CALL|AUTHOR|TITLE)/ } < +FILE>;

    holli, regexed monk
Re: print spaces with grep
by prasadbabu (Prior) on Jan 19, 2005 at 11:20 UTC

    The question is not clear, if you post the input and the output required correctly, it will be useful for us to answer your question correctly.

    Prasad