in reply to what does goto ""; mean?

It seems that goto ""; and goto "\x00"; have the same behaviour. Peeking in the sources of Perl, one sees several *label tests (a test which is false if label points to a NUL character). This might explain why Perl isn't complaining (although the source for goto is long and most of it I don't understand), but it doesn't explain why the warn 2 isn't executed.

Abigail

Replies are listed 'Best First'.
Re: Re: what does goto ""; mean?
by pg (Canon) on Dec 11, 2003 at 16:24 UTC

    Just to add on top of what Abigail-II mentioned (why it is worth to mention "\x00"?).

    If Perl, "" and "\x00" are not the same: (for people from c background, this is different in Perl and c.)

    use strict; use warnings; if ("\x00" eq "") { print "they are the same"; } else { print "they are not the same"; }

    But they are the same in c/c++:

    #include <iostream.h> int main() { if (!strcmp("", "\x00")) { cout << "they are the same" << endl; } else { cout << "they are different" << endl; } }
      Careful. They're treated the same in C, but they're not. The difference between "" and "\x00" is that the former is one byte long, whose value is null, while the latter is two bytes long - two nulls. But since everything in C treats a null as end-of-string, the difference is not apparent anywhere.

      Makeshifts last the longest.

        This is the synergy of a cyber-team. We are together adding blocks to build our tower.

        Obviously I agree with you. The actually memory setting of “” and “\x00” are different, but the interpretation (when it is exposed to programmers as string) in c is the same. We can actually see two layers:

        • The actual data storage in memory
        • The interpretation offered by the language
        The difference between "" and "\x00" is that the former is one byte long, whose value is null, while the latter is two bytes long - two nulls.
        The character '\0' is the NUL (single L) character. NULL (double L) is a pointer, not a character.

        Abigail

Re: Re: what does goto ""; mean?
by ambrus (Abbot) on Dec 12, 2003 at 07:21 UTC

    Thanks for explaining the empty label.

    About goto "", I've just noticed that $u= ""; goto $u; does not have this wierd beheaviour (it dies with the correct message), so maybe goto ""; isn't a computed goto at all. Notice that a computed last is illegal, but last "label"; or even last ("label".""); does work, as ("label"."") is a constant expression.