in reply to Value of a scalar specified by a second scalar

You're talking about symbolic references. The syntax you are looking for is just like that for real references.

$c = 'foo'; $want = 'c'; print $$want, $/;
Strictures will complain about symrefs and fail to run. As you say, usually a hash is wanted when they are introduced.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Value of a scalar specified by a second scalar
by ruzam (Curate) on May 18, 2006 at 03:51 UTC
    Is there any reason or benefit to prefering
    print $$want, $/;
    over
    print $$want, "\n";
    I find myself tacking "\n" on the end of prints more often then I think I should.
    Just wondering if there's a better way.

      Only minor advantages. It's two fewer keystrokes and it makes output conform to the current input record seperator, which is sometimes good to ensure.

      Mainly, it's one of my coding habits. I formed it under the superstition that it's more platform neutral. That's not really true, but the minor advantages win for a habit I've already got.

      The truly handy way to stop fussing with newlines is to set local $\ = "\n"; and know that all distinct prints in that scope will get newlines appended.

      $ perl -e'local $\ = $/; print for qw/foo bar baz/' foo bar baz $

      After Compline,
      Zaxo