in reply to Re^4: Filehandle/array naming
in thread Filehandle/array naming

I was under the impression that in this case brackets around a variable name are just to clarify things and $x was a synonym to ${x}. Is ${x.$y} a special case? https://perldoc.perl.org/perlref#Not-so-symbolic-references calls that a not-so-symbolic reference! Tomorrow I will post a question as I am still confused on the boundaries.

thanks

Replies are listed 'Best First'.
Re^6: Filehandle/array naming (updated)
by AnomalousMonk (Archbishop) on Nov 20, 2020 at 17:26 UTC

    JSAWS seems to be running without strictures (and warnings?) enabled, so the OPed code seems to be using honest-to-goodness symbolic references.

    Win8 Strawberry 5.8.9.5 (32) Fri 11/20/2020 12:19:01 C:\@Work\Perl\monks >perl # strictures and warnings not enabled $n = 99; ${ foo . $n } = 'zot'; print $foo99; ^Z zot
    This is the general case in these circumstances (and one of the motivations for the creation of strict).

    Update: The { } brackets in ${ foo . $n } are required for disambiguation. The statement
        $foo . $n = 'zot';
    produces a very different result.


    Give a man a fish:  <%-{-{-{-<

      My confusion is: where does using { } brackets for disambiguation (as in print 'aa${foo}bb') stop and symbolic references start as in ${foo.$n} or ${foo.''} . Did I get { } brackets for disambiguation wrong (e.g. as in the unix shell use-case: ${XYZ} )?

        If the thing inside the brackets is a single identifier, it's the disambiguation. If it's more, i.e. there is an operation involved (like concatenation in this case), it's the symbolic reference.
        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        As I understand it, symbolic referencing starts when you start generating symbols at run time. After all, in the statement
            my $foo = 'bar';
        foo is a symbol, an identifier or name. There might be other variables with the same name, distinguished by their sigils, but all this is known at compile time.

        The other distinguishing feature of old-school symbolic referencing in Perl is that it only applies to package-globals.

        Of course, the barrier between compile time and run time is very permeable in Perl, and one can slip back and forth between these states in all kinds of tricksy (and useful) ways. Using eval, one can manufacture endless symbols and syntax for functions, variables and so on and build entire programs at run time. All of this run-time compilation goes on within appropriate scoping constraints, whereas "symbolic referencing" (as the term is used in Perl) for package-globals is always... well, global.


        Give a man a fish:  <%-{-{-{-<