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

I WISH:
Perl would allow me to use labels indiscriminately in code.

Example:

#!/usr/blap/perl -w
L000:
L001: use strict;
L002:
L003: print "Hello World!\n";

But of course, "use strict" should complain about them.

This way you could have line numbers. Okay maybe it's silly. It would be another way to comment too. It seems unperlesque to not allow me to throw around as many labels as I want. I don't see a good reason for this behavior. Or is this fixed in the latest version?

--
-ken rich       "I'm continually AMAZED at
                 th'breathtaking effects of
                 WIND EROSION!!"  (Zippy) 
  • Comment on unused labels should not halt compilation

Replies are listed 'Best First'.
Re: unused labels should not halt compilation
by Beatnik (Parson) on May 27, 2002 at 14:55 UTC
    Well, there's always Source code line numbering :)
    Should get on CPAN sometime around 18-19-20 September 2002 :)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: unused labels should not halt compilation
by samtregar (Abbot) on May 27, 2002 at 19:31 UTC
    I get a syntax error running your code:

    $ perl label.pl syntax error at label.pl line 3, near "L001:" Execution of label.pl aborted due to compilation errors.

    But I'm not really sure what the problem is. Maybe labels are only legal on blocks? But adding blocks only makes the error weirder:

    syntax error at label.pl line 3, near "L001" "use" not allowed in expression at label.pl line 3, near "{ " Execution of label.pl aborted due to compilation errors.

    -sam

Re: unused labels should not halt compilation
by Juerd (Abbot) on May 27, 2002 at 20:00 UTC

    (Update)You can only add a label to a blockYou can't add a label to use, so line numbering everything is out of the question.

    Why on earth do you want line numbers? goto LABEL is bad, and if you feel line numbers are the ultimate way of structuring your code, maybe a nice tutorial can make you think clear again.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      a smidgen of creative blocking lets you number use as well.
      #!/usr/bin/perl -w L000: { use strict; L001: {use Quantum::Superpositions} L002: my $foo = all(1,2,3); L003: $foo *= 2; L004: print "Here I am\n"; L005: goto L003 unless all($foo) > 10; L006: print "$foo"; L007: }
      Funny, this runs perfectly fine with my Perl 5.6.1
      #!/usr/bin/perl -w use strict; L000: my $i = 1; L001: print "Here I am\n"; L002: goto L001 unless $i++ > 10; L003: print "Done\n";
      and nary a block in sight
A reply falls below the community's threshold of quality. You may see it by logging in.