in reply to Re: ::'s role in strings
in thread ::'s role in strings

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?

Replies are listed 'Best First'.
Re^3: ::'s role in strings
by ikegami (Patriarch) on Apr 27, 2006 at 18:58 UTC

    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'

        Double quoted strings are bad in shells, as '$a' might be processed by the shell,

        That bit is false. Double quotes are required by my shell. $ does not have a special meaning for it, and single-quoting the argument does not work. Your statement should read:

        Double quoted strings are bad in some shells, as '$a' is processed by them,

        I'm sure you're right that double-quoted strings are bad for his shell (and it, not perl, produced the error he posted).