in reply to Isn't there a print line function?

How about a regex with the /m modifier like this:

$/ = "\n\n"; # set to grab whole paragraphs, not lines my @paras = <DATA>; my $whatever = qr/paragraph/; for (@paras) { print "$1$2$3\n" if /^(.*)($whatever)(.*)$/m; } __DATA__ This is the first paragraph And paragraph two is here Here is the third paragraph to wrap it up

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Isn't there a print line function?
by davorg (Chancellor) on Sep 04, 2001 at 19:55 UTC

    There's a difference between setting $/ to "\n\n" and and empty string. In this case, the empty string would probably be better. Also your regex line is far too complicated. I'd write this code as follows:

    $/ = ''; # set to grab whole paragraphs, not lines my @paras = <DATA>; my $whatever = qr/paragraph/; for (@paras) { print if /$whatever/m; } __DATA__ This is the first paragraph And paragraph two is here Here is the third paragraph to wrap it up
    --
    <http://www.dave.org.uk>

    Perl Training in the UK <http://www.iterative-software.com>

      While I will agree that '' is probably better you are wrong on the regex. You just dump the whole paragraphs. The task (I believe) was only to dump the single *line* within that paragraph that contained the match which is what my example does.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print