in reply to ::'s role in strings

It means you can do the following:

>perl -e "$a = Class::; print $a" Class

It even works under strict, and it's doesn't issue any warnings if the package exists.

Replies are listed 'Best First'.
Re^2: ::'s role in strings
by eff_i_g (Curate) on Apr 27, 2006 at 18:56 UTC
    Here is what I tried on my machine:
    > perl -v This is perl, v5.8.6 built for PA-RISC2.0 Copyright 1987-2004, Larry Wall ... > perl -e "$a = Class::; print $a" a: Undefined variable.
    I guess my follow up question is: Why does/should this work?

      I used 5.6.1.

      a: Undefined variable.

      I'm susprised by the output you get. Is that really what you got for output? from perl? No, it's from your shell. Use single quotes.

      Why does/should this work?

      It's probably just an unintentional side-effect. It's to avoid ambiguitities when using indirect method calls. I wouldn't use :: as a quoting mechanism.

      Updated: Thanks to japhy and jhourcle for the corrections/elaborations.

        It works so that you can write:
        use Foo; # defines Foo::new() among others sub Foo { "Oh no, Mr. Bill!" } $x = new Foo::;
        because $x = new Foo would NOT work under those circumstances.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        Oops. The shell problem should have been obvious--sorry about that. Thanks for clearing this up everyone.

        I'm not surprised at all. Double quoted strings are bad in some shells, as '$a' might be processed by the shell, not by perl, therefore, might result in a shell error.

        $ perl -v This is perl, v5.8.6 built for darwin-thread-multi-2level (with 2 registered patches, see perl -V for more detail) ... $ perl -e "$a = Class::; print $a" syntax error at -e line 1, near "=" Execution of -e aborted due to compilation errors. $ perl -e '$a = Class::; print $a' Class

        Update: inserted word 'some'