in reply to Using list elements within lists contexts with the distributive properties of HTML shortcuts

regarding the part where you said:

I tried $_ and $list. The former produces no errors and no ouput. The latter (with -w and strict in force) gives:
Global symbol "$list" requires explicit package name at ...

When you use strict, you need to explicitly qualify variable names. If you haven't defined a package yourself you can simply put "main::" before your globals. Or, define vars with 'my' to avoid that.

I hope that helps (and I hope that last part of what I said is correct :^)

-X
  • Comment on Re: Using list elements within lists contexts with the distributive properties of HTML shortcuts

Replies are listed 'Best First'.
Re: Re: Using list elements within lists contexts with the distributive properties of HTML shortcuts
by Anonymous Monk on Jun 09, 2002 at 22:23 UTC

    True. And (for the first time here:), I actually knew that.

    However, as I understand it, when I defined my @list, I actually defined a typeglob named *list which contains one each of a scaler, an array, a list and a hash all named list (and accessable locally with the appropriate funny character prefix).

    Moreover, when one iterates over @list using one of the foreach or for...in constructs, the scaler $list is automagically (sorry. I forgot the correct term) set to the next value from @list at each iteration. Hence, my attempt to use that.

    The problem in this case (thanks to jeffa!), is that the iteration in being performed outside of my scope, so $list is never being set.

    At least that is my understanding at this point. Maybe someone will correct me if I have this wrong.

      You have that wrong. :) Witness:
      my $list = 'some default item'; my @list = (1, 2, 3, 4); foreach (@list) { print "$list\n"; }
      If you change the print line to print "$_\n";, you'll see the aliasing in effect. (It doesn't matter whether you use for or foreach, as they're synonyms.)

      Of course, there's a deeper misunderstanding, namely that declaring a lexical does not create what most people in the know might consider a typeglob (at least, not in a symbol table. It's put in a pad.). Nor are the values pointed to by typeglob slots automatically populated by iterating over an aggregate of the same name.

      It is true that when you do cause a new typeglob to be created, it does automagically get a new scalar in the appropriate slot, but that's done as an optimization, and not for any aliasing.

        Proof if ever it were needed that a little knowledge is a dangerous thing

        Just as I think I can run, I get sacked!

        Thanks for putting me straight and my apologies for contradicting those that know better than me.