RE: Using strict and configuration files

2002-06-11 Thread Bob Showalter

> -Original Message-
> From: Camilo Gonzalez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 11, 2002 10:21 AM
> To: 'Bob Showalter'; Camilo Gonzalez; [EMAIL PROTECTED]
> Subject: RE: Using strict and configuration files
> 
> 
> So the following are equivalent:
> 
> use vars qw(foo)
> 
> our $foo = ""

Pretty much. The latter has an initializer, which the first doesn't.
The scoping rules are also slightly different.

But yes, "our" is basically a replacement for "use vars".

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using strict and configuration files

2002-06-11 Thread Camilo Gonzalez

So the following are equivalent:

use vars qw(foo)

our $foo = ""

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 11, 2002 9:17 AM
To: 'Camilo Gonzalez'; [EMAIL PROTECTED]
Subject: RE: Using strict and configuration files


> -Original Message-
> From: Camilo Gonzalez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 11, 2002 10:16 AM
> To: 'Bob Showalter'; 'Octavian Rasnita'; [EMAIL PROTECTED]
> Subject: RE: Using strict and configuration files
> 
> 
> Bob,
> 
> Exactly what does "our" do? I understand "my" and even 
> "local" but have yet
> to grasp the "our" concept.

It just declares that a global variable will be used without a
qualifying package name. Basically, it makes "use strict" happy.

perldoc -f our

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using strict and configuration files

2002-06-11 Thread Bob Showalter

> -Original Message-
> From: Camilo Gonzalez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 11, 2002 10:16 AM
> To: 'Bob Showalter'; 'Octavian Rasnita'; [EMAIL PROTECTED]
> Subject: RE: Using strict and configuration files
> 
> 
> Bob,
> 
> Exactly what does "our" do? I understand "my" and even 
> "local" but have yet
> to grasp the "our" concept.

It just declares that a global variable will be used without a
qualifying package name. Basically, it makes "use strict" happy.

perldoc -f our

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using strict and configuration files

2002-06-11 Thread Camilo Gonzalez

Bob,

Exactly what does "our" do? I understand "my" and even "local" but have yet
to grasp the "our" concept.

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 11, 2002 9:12 AM
To: 'Octavian Rasnita'; [EMAIL PROTECTED]
Subject: RE: Using strict and configuration files


> -Original Message-
> From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 28, 2000 4:32 AM
> To: [EMAIL PROTECTED]
> Subject: Using strict and configuration files
> 
> 
> Hi all,
> 
> I want to use:
> 
> use strict;
> 
> And I want to use a configuration file in a Perl script.
> The configuration file uses:
> %page1=(
> 
> );
> 
> %page2=(
> 
> );
> 
> This way I get errors if I run the script because the 
> variables are not
> defined with "my".
> 
> I've tried putting in the configuration file:
> 
> my %page1=(
> 
> );
> 
> But this method doesn't work.
> 
> I use a configuration file and I would like to put the 
> settings only in this
> file without modifying the script.
> 
> Is it possible?

Yes.

In your main program:

   use strict;
   require "config.pl";
   our ($foo);

   print "foo is $foo\n";

In your config file:

   $foo = "Hello, world";

"use strict" applies only to the current file, so you don't need to
change your config file. You need to add the "our" declaration to
your main program to make "use strict" happy.

A more formal way to handle this would be to use a module and import
symbols:

File MyConfig.pm:

   package MyConfig;

   use strict;
   require Exporter;
   our @ISA = qw(Exporter);
   our @EXPORT = qw($foo);

   our $foo = "Hello, world";   

   1;

Main program:

   use strict;
   use MyConfig;

   print "foo is $foo\n";

If you import a symbol with "use", you don't need the "our" declaration.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Using strict and configuration files

2002-06-11 Thread Bob Showalter

> -Original Message-
> From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, May 28, 2000 4:32 AM
> To: [EMAIL PROTECTED]
> Subject: Using strict and configuration files
> 
> 
> Hi all,
> 
> I want to use:
> 
> use strict;
> 
> And I want to use a configuration file in a Perl script.
> The configuration file uses:
> %page1=(
> 
> );
> 
> %page2=(
> 
> );
> 
> This way I get errors if I run the script because the 
> variables are not
> defined with "my".
> 
> I've tried putting in the configuration file:
> 
> my %page1=(
> 
> );
> 
> But this method doesn't work.
> 
> I use a configuration file and I would like to put the 
> settings only in this
> file without modifying the script.
> 
> Is it possible?

Yes.

In your main program:

   use strict;
   require "config.pl";
   our ($foo);

   print "foo is $foo\n";

In your config file:

   $foo = "Hello, world";

"use strict" applies only to the current file, so you don't need to
change your config file. You need to add the "our" declaration to
your main program to make "use strict" happy.

A more formal way to handle this would be to use a module and import
symbols:

File MyConfig.pm:

   package MyConfig;

   use strict;
   require Exporter;
   our @ISA = qw(Exporter);
   our @EXPORT = qw($foo);

   our $foo = "Hello, world";   

   1;

Main program:

   use strict;
   use MyConfig;

   print "foo is $foo\n";

If you import a symbol with "use", you don't need the "our" declaration.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Using strict and configuration files

2002-05-29 Thread Carl Franks

Hi,
This is how I do it.

#!/usr/bin/perl -wT
use strict;
my $conf;

unless ($conf = do ('/path/to/config.pl')) {
  die ("Could not open file");
}

print $conf->{'var1'}, "\n";

-

Then in a file called "config.pl"


{
  var1 => "one",
  var2 => "two"
}

-

The "unless" part is just to check that the file was opened successfully.
The "do" actually opens the file and assigns the hash structure to $conf.

Hope this helps!
Carl

> Hi all,
>
> I want to use:
>
> use strict;
>
> And I want to use a configuration file in a Perl script.
> The configuration file uses:
> %page1=(
> 
> );
>
> %page2=(
> 
> );
>
> This way I get errors if I run the script because the variables are not
> defined with "my".
>
> I've tried putting in the configuration file:
>
> my %page1=(
> 
> );
>
> But this method doesn't work.
>
> I use a configuration file and I would like to put the settings only in this
> file without modifying the script.
>
> Is it possible?
>
> Thanks.
>
> Teddy,
> [EMAIL PROTECTED]
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]