in reply to whats wrong with this break ?

The issue is that break is not a keyword in Perl. You mean last. For a basic intro to how to control programmatic flow in Perl, see Loop Control in perlsyn.

If you had used strict, Perl would have told you as much.

use strict; use warnings; while (<STDIN>) { print "--> $_"; if ( /^2/ ) { break; } print "--> $_"; } while (<STDIN>) { print "==> $_"; }

yields

Bareword "break" not allowed while "strict subs" in use at fluff.pl li +ne 7. Execution of fluff.pl aborted due to compilation errors.

Please read Use strict warnings and diagnostics or die (and The strictures, according to Seuss for a chuckle) to understand why strict will make your life dramatically easier.

Replies are listed 'Best First'.
Re^2: whats wrong with this break ?
by TomDLux (Vicar) on Sep 17, 2010 at 16:54 UTC

    Ironically, you were right for years, decades, but as of 5.10 break IS a keyword in Perl. Just goes to show .... something.

    25$ perldoc -f break break Break out of a "given()" block. This keyword is enabled by the "switch" feature: see fe +ature for more information.

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.