${$indirect} = $new doesn't work? 
Author Message
 ${$indirect} = $new doesn't work?

Suppose $indirect="b";

And I would like to assign $b=$newvalue indirectly like
        ${$indirect}=$newvalue
but it doesn't work. But calling sub with &$indirect() works fine.
Thanks for the help.

--pan



Wed, 19 Jun 1996 09:51:03 GMT  
 ${$indirect} = $new doesn't work?
I asked:

Quote:
> Suppose $indirect="b";
> And I would like to assign $b=$newvalue indirectly like
>         ${$indirect}=$newvalue
> but it doesn't work. But calling sub with &$indirect() works fine.

After reading the thread regarding addressing the package, I tried the
following ways:
1. $indirect="bar";
   eval "\${$indirect}=$newvalue";

2. *indirect = "bar";
   $indirect = $newvalue;

Both successfully assign $newvalue to $bar.
But can any kind soul explain to me why 'eval' and '*' work fine but the
original method fails?

Thanks and happy New Year!

--pan



Wed, 19 Jun 1996 21:05:56 GMT  
 ${$indirect} = $new doesn't work?

:Suppose $indirect="b";
:
:And I would like to assign $b=$newvalue indirectly like
:        ${$indirect}=$newvalue
:but it doesn't work. But calling sub with &$indirect() works fine.
:Thanks for the help.

You're making the mistake of assuming a greater degree of syntactic
consistency than Perl actually provides you.  

Predictability is perhaps Perl's pre{*filter*} problem as a programming
language (modulo the long-sought data structures and references introduced
in Perl 5).  With frustrating frequency, it is ineffectual to attempt to
observe a particular kind of behavior in one point, derive an hypothetical
operational model, apply that model to other areas in the language, and
have this actually behave according to your expectations.

In short, just because

    &func();  
    $blah = 'func';
    &$blah();

work does not itself imply that

    $foo;
    $foo = 'bar';
    $$foo;  # access $bar

should also work.  In Perl0..Perl4, it doesn't.

Perl5 makes many things consistent, including this.  It works in Perl5.

--tom
--

      "Will Hack Perl for Fine Food and Fun"
        Boulder Colorado  303-444-3212



Thu, 20 Jun 1996 03:31:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Win32::ODBC; NEW doesn't work

2. (new Win32::ODBC($DSN1)) doesn't work

3. WIN32::ODBC new() doesn't work

4. new Module LEntry.pm doesn't work inside ROText

5. Directory handling script works and doesn't work

6. ODBC.PM and sql's Like doesn't work

7. UNIVERSAL doesn't work how I'd expect

8. UNIVERSAL doesn't work how I'd expect

9. open'ing lynx doesn't work when called by cron

10. http proxy in chroot'ed environment doesn't work - help

11. Apache, embperl, mod_perl : require doesn't work and can't write to file

12. UNIVERSAL doesn't work how I'd expect

 

 
Powered by phpBB® Forum Software