[tpm] Using a variable in a 'qw()'

Madison Kelly linux at alteeve.com
Thu Jun 12 12:37:41 PDT 2008


Michael Graham wrote:
> 
> when you say: 
> 
>    my $foo="org.tle_bu.Clients";
>    use Net::DBus::Exporter ($foo);
> 
> It is really the equivalent of:
> 
>     my $foo="org.tle_bu.Clients";
>     BEGIN {
>         require Net::DBus::Exporter;
>         Net::DBus::Exporter->import($foo);
>     }
>    
> And the BEGIN block gets run before you assign to $foo.  Which is not what you
> want.
> 
> Instead, do this:
> 
>     my $foo;
>     BEGIN {
>         $foo="org.tle_bu.Clients";
>     }
>     use Net::DBus::Exporter ($foo);
> 
> Or:
> 
>     my $foo="org.tle_bu.Clients";
>     require Net::DBus::Exporter;
>     Net::DBus::Exporter->import($foo);
> 
> 
> Michael

Thanks, Michael!

   Using:

require Net::DBus::Exporter;
Net::DBus::Exporter->import($$conf{dbus}{interface}{clients});

   Worked, thanks! I hadn't realized the difference between 'use' and 
'require' until I saw that 'use Net::DBus::Exporter' didn't work. Yay 
'perldoc -f use'! :)

Madi


Madi


More information about the toronto-pm mailing list