[clug] perl question
Francis James Whittle
fudje at phreaker.net
Mon Oct 18 02:23:10 GMT 2004
Not that this is really the best solution, but you could use explicit
package namespaces to get around that. Either just use main, like
instead of 'my $scalar; my @list;' you could use '$main::scalar;
@main::list;', or have a configuration package, say 'MyConfig', which
would be like:
package MyConfig;
$MyConfig::scalar;
@MyConfig::list;
%MyConfig::hash;
Another possibility is to have your configuration fragment return a
(possibly bless()'d, but it's really pointless) hash reference. If
memory serves, this is done something like:
# package MyConfig;
my $self = (
foo => 'bar',
bar => 'baz',
);
# bless ($self, MyConfig);
return $self;
If you *are* going to bless() it, that'll obviously work better with an
actual constructor. In the long run, a properly constructed
configuration object will look clearer than a reference returned from a
file in a big ol' do statement (and will result in less superfluous
colons), and it still doesn't *need* to be bless()'d. There are other
benefits too, like different constructors for different conditions, etc.
Can't help you with the debug command, maybe perldoc can ;)
Francis
On Mon, 2004-10-18 at 10:17 +1000, Kim Holburn wrote:
> Hi Guys,
>
> I was wondering if one of you perl guys out there could throw some
> light on this question.
>
> I have a perl script with a config file. Recently it seemed to me that
> it would be better to make the config file a perl fragment, (it just
> does some variable assignments) and use a "do" statement to read it in.
>
> Unfortunately it messes with my declarations. If I declare the
> variables anywhere in a "my" declaration the assignments don't work.
> If I don't declare anything it all works OK. I like to work under
> "strict" but this doesn't any work more. Something about packages? I
> never really understood about packages. Do I have to declare these
> local or something else?
>
> Is there a debug command to show all variables and what type they are?
>
> Kim
>
> --
> Kim Holburn
> IT Manager, Canberra Research Laboratory
> National Information and Communication Technology Australia
> Ph: +61 2 61258620 M: +61 417820641
> Email: kim.holburn at anu.edu.au - PGP Public Key on request
> Cacert Root Cert: http://www.cacert.org/index.php?id=16 ->
> http://www.cacert.org/cacert.crt
> Aust. Spam Act: To stop receiving mail from me: reply and let me know.
>
> Democracy imposed from without is the severest form of tyranny.
> -- Lloyd Biggle, Jr. Analog, Apr 1961
>
More information about the linux
mailing list