Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Surely:

    is "$french_for{'$num'}", 'un', 'single quoted variable key';

    Will fail. You've single quoted '$num' hence you're looking for the key "\$num".
    • Yes, that's the failure, but I don't know why that should be obvious because if you add diag "'$num'" to the end of that script, you get this:

      # 'one'

      In other words, a variable in single quotes will interpolate if it's embedded in a double quoted string but not used as the key to a hash or an index into an array. That seems a bit odd and it would be nice if it were documented better. I should submit a patch for perltrap if it's not documented.

      • a variable in single quotes will interpolate if it's embedded in a double quoted string but not used as the key to a hash or an index into an array. That seems a bit odd

        Actually what seemed odd to me was that the first example (with single quotes around the literal) worked OK. But given that, I did expect it to fail round a variable (as in I guessed what the failure would be before even seeing your list of choices).

        Yes directly in a double-quoted string literal single quotes don't prevent a variable between them from being interpolated, but then those single quotes do do something: they end up in the output.

        You've already established that single quotes inside a hash key inside double quotes are different from single quotes directly inside double quotes because they are not taken literally; the key was one, not 'one'.

        So that shows that in that circumstance the quote marks are actually behaving like quote marks rather than merely as literal characters, in which case it seems consistent and predictable that they would act in the way that single quotes do everywhere else and not permit interpretation.

        Smylers

        • Well, basically the stuff after a $ or @ sigil gets treated sort of like it's code to be executed. This leads to the following:

            temp $ touch foo.bar
            temp $ ls
            foo.bar
            temp $ perl -e 'print "$ENV{`rm foo.bar`}"'
            temp $ ls
            temp $

          I know you and I have discussed this bit, but others might want to be aware of it.