in reply to Re: Soft Array Refs
in thread Soft Array Refs

Ah so,

I was somewhat close. I'm still fairly clueless on some of the syntactical subtleties in Perl - single quotes around '@table' for example. I love your printing shortcut at the end - I learn something new everyday. I'm looking to write this code CORRECTLY using hashes instead.

Thx, Joe

Replies are listed 'Best First'.
Re^3: Soft Array Refs
by AnomalousMonk (Archbishop) on Jun 24, 2015 at 18:33 UTC
    ... single quotes around '@table' ...

    If double-quotes has been used, double-quotish interpolation of an array named  @table_ would have been attempted and, with strict fully enabled (as it is in Athanasius's code), would have crashed compilation. Single-quotes do not interpolate. (Update: The  @ sigil could also be escaped in double-quotes.)

    c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; print qq{@table}; " Possible unintended interpolation of @table in string at -e line 1. Global symbol "@table" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my @table = qw(fee fie foe); ;; print qq{double-quote array interpolation: (@table)}; ;; print q{single-quote, no interpolation: (@table)}; ;; print qq{double-quote, sigil escaped: (\@table)}; " double-quote array interpolation: (fee fie foe) single-quote, no interpolation: (@table) double-quote, sigil escaped: (@table)

    Update: Changed code examples to consolidate compiling code examples into single group of statements.


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

      Correct.

      I noticed this after it failed the first time and I looked closer at Athanasius's code. Gvim's context-sensitive color-coding also clued me in to what was going on.

      As a follow-up, I was very successful in coding this as a nested hash - it took very little time and I was quite pleased at how easy it was. It was far less code than my previous attempt using if-statements and arrays AND no soft references!