in reply to qw "$string $string" doesn't interpolate

juerd@ouranos:~$ perl -MO=Deparse -e'print qw(a b c)' print 'a', 'b', 'c'; -e syntax OK
qw is expanded before the code runs. At that time, variables usually have no value yet. Interpolation would mean delaying until runtime, of having very unexpected results. Of course, it could still optimize for the variableless case, but that would mean that qw($foo $bar) is many times slower than qw(foo bar).

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re^2: qw "$string $string" doesn't interpolate
by QM (Parson) on Jun 14, 2004 at 19:46 UTC
    ++

    So q, qq, qx, and qw aren't captured in the structure that Deparse operates on. You could almost say they were source filters. Which is efficient, but not what I was hoping for.

    So getting qw"$string" to interpolate doesn't look like an oversight, it's a result of the implementation. I can't see a good reason to change it, given there's a work around for my "problem" [laziness], and existing code could break.

    [Makes me wonder how many qw"$string" occurrences there are in existing code?]

    Thanks,

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      So q, qq, qx, and qw aren't captured in the structure that Deparse operates on.

      That structure is the bytecode. Perl doesn't directly execute your code. It first compiles the thing to bytecode and then executes that in the virtual machine. This all happens transparently. B::Deparse translates (or at least tries to) the bytecode back to readable Perl.

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }