in reply to How to use Labels

A label can be placed on any basic BLOCK, or any of the looping statements (while, for, and foreach). The "Compound Statements" section in perlsyn has the details. So, no, you can't do this: LINE: flock(FILE, 2) or goto LINE; You could do it enclosing the statement in curly braces to make a block, but that whole statement horrifies me so much that I'm not going to show you how. ;-)

BTW, labelled blocks are one way you can create "switch" statements in Perl. Continue down perlsyn to the section named "Basic BLOCKs and Switch Statements" for several examples.

HTH

Updated by VSarkiss:
My bad. Hofmator is right. You can put labels on single statements like your example. I need to test before I hit "submit"....

Replies are listed 'Best First'.
Re: Re: How to use Labels
by srawls (Friar) on Jun 19, 2001 at 20:57 UTC
    So, no, you can't do this: LINE: flock(FILE, 2) or goto LINE;

    Why not? Try this out and see what it prints:

    $i = 5; LINE: print "got here\n"; --$i and goto LINE;

    The 15 year old, freshman programmer,
    Stephen Rawls