[tpm] Using a variable in a 'qw()'
Mike Stok
mike at stok.ca
Thu Jun 12 09:33:55 PDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12-Jun-08, at 10:25 AM, Madison Kelly wrote:
> Hi all,
>
> I want to use a variable when calling a module that uses the 'qw()'
> syntax. Specifically:
>
> use Net::DBus::Exporter qw(org.tle_bu.Clients);
>
> I would like to be able to say:
>
> my $foo="org.tle_bu.Clients";
> use Net::DBus::Exporter qw($foo);
>
> But '$foo' is passed in directly, rather than it's value. Is there
> an
> alternative to 'qw()'? Honestly, I use that syntax all the time but
> I've
> never really understood how it works. Perhaps I should be asking for a
> pointer to a doc that explains this syntax better?
>
> Thanks, as always!
In addition to the things other people have mentioned, you need to be
aware of when variables get set. use is a BEGIN time thing, so
#!/usr/bin/env perl
use strict;
use warnings;
my $var = ':standard';
use CGI ($var);
print header;
doesn't do what I intended, and I need to do this to make sure $var is
set before the use happens (or something similar depending on what you
want the scoping of $var to be):
#!/usr/bin/env perl
use strict;
use warnings;
my $var;
BEGIN { $var = ':standard'; }
use CGI ($var);
print header;
Hope this helps,
Mike
- --
Mike Stok <mike at stok.ca>
http://www.stok.ca/~mike/
The "`Stok' disclaimers" apply.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iEYEARECAAYFAkhRT/MACgkQnsTBwAWZE9oEYwCaAs7fBTfkdGHWRjZ5U9347D4L
6QwAn3vWfzdxW1zLlqODp0FjJL6gEDD9
=Aa5Q
-----END PGP SIGNATURE-----
More information about the toronto-pm
mailing list