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

I tried to understand the difference between -n and -p in perl.

Both has while loop surrounded, which reads the input line by line using diamond operator, and has the code executed for each line ( program inside that loop ). And the only difference is -n suppresses printing, and -p prints $_ by default.

But i got confused from this explanation in the man page, man perlrun which says,
LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
I've never used continue like the above, and not able to understand what the above means ? Please explain what does the above code means, and is there any other difference between -n and -p.

Replies are listed 'Best First'.
Re: what is -p option in perl does ? Confused with man perlrun.
by moritz (Cardinal) on Aug 24, 2010 at 08:39 UTC
    See the documentation for continue: It executes the code in the following block after each iteration of the loop, even if it was aborted by last or next.
    and is there any other difference between -n and -p.

    I don't think so.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: what is -p option in perl does ? Confused with man perlrun.
by Corion (Patriarch) on Aug 24, 2010 at 08:41 UTC

    Maybe you are confused about the continue keyword? This is what -p uses to implement its functionality.