[Techtalk] Perl Frustration

Kai MacTane kmactane at GothPunk.com
Fri Oct 31 17:18:39 EST 2003


At 10/31/03 10:19 AM , Almut Behrens wrote:

>the feature you're using here to define new variables at runtime is
>named "symbolic references", and those in principle do not work with
>my-variables

I knew that, I just didn't know why, or what to use instead.

>(reason is, among others, that my-vars have no associated
>symbol table).

Ah, so that's why! Thank you.

>(1) locally disable strict checking for the symbolic references:
>
>   ...
>       no strict 'refs';   # allow symbolic refs for the next two lines
>       $main::foovar = $thisline.'_foo';
>       $$main::foovar = $thisline;

Ah, I have to explicitly reference $main:: -- thanks!

>this can, btw, also be written somewhat shorter as follows, not
>requiring the intermediate variable $foovar

I tried to do that, but couldn't get the braces and stuff right.

>(2) use eval to define the new variables at runtime:
>
>   ...
>     eval "\$main::${thisline}_foo = '$thisline'";

Do you have any opinion on which would be more readable and understandable 
to the average Perl coder?

>Also, note that, in all cases you need to fully qualify the variable
>names (i.e. prefix them with "main::", or whatever package they're in),
>if you cannot predeclare them.

Thanks for all your help!

                                                 --Kai MacTane
----------------------------------------------------------------------
"Spiderwebs of steel and stone subdivide our given home,
  Remembrance of ancestrous age,
  Thorns and brambles of a different age.
  We will not be thrown away; we will not be torn,
  We will never fall astray; we've seen your kind before."
                                                 --Abney Park,
                                                  "Thorns & Brambles"



More information about the Techtalk mailing list