[32972] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4248 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 10 21:09:18 2014

Date: Thu, 10 Jul 2014 18:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 10 Jul 2014     Volume: 11 Number: 4248

Today's topics:
        Keeping data and code separate in a module <cal@example.invalid>
    Re: Keeping data and code separate in a module <gamo@telecable.es>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 10 Jul 2014 15:25:53 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Keeping data and code separate in a module
Message-Id: <c28i7iF5trmU1@mid.individual.net>

Hello ng,

I'm revamping my templates for producing html pages.  Every project has 
its cloned version of template_stuff, where it finds everything it needs 
to build a page and put it on my domain space.

$ cd template_stuff/
$ cat choir3.pm
#!/usr/bin/perl -w
package choir3;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw( print_hash
      get_ftp_object  highest number
  get_content get_html_filename
create_html_file write_header
    write_footer write_script);

our %config = (
      my_ftp =>  {
            domain   =>  '',
            username =>  '',
            password =>  '',
           },

     usenet =>  {
            domain   =>  '',
            username =>  '',
            password =>  '',
           },
);

sub get_html_filename{
use strict;
use Net::FTP;
use File::Basename;
use Cwd;

 ....


This works great, but I can't show anyone this module without also 
showing them my ftp data.  It was best form to move these data away from 
the .pl script and into the .pm, but now I'd like to have a .pm for 
these data alone, and I'm not able to achieve that.

My idea was to have a use statement at the beginning of the .pm

$ cat revamp1.pm
#!/usr/bin/perl -w
package revamp1;
require Exporter;
use config1;
 ...

$ cat config1.pm
#!/usr/bin/perl -w
package config1;
require Exporter;

our @ISA = qw(Exporter);

our %config = (
      my_ftp =>  {
            domain   =>  're',
            username =>  'dac',
            password =>  'ted',
           },

);


$

Perl doesn't like the "our" variable being in a used package:

$ perl revamp1.pl
Global symbol "%config" requires explicit package name at 
template_stuff/revamp1.pm line 66.
Global symbol "%config" requires explicit package name at 
template_stuff/revamp1.pm line 67.
Global symbol "%config" requires explicit package name at 
template_stuff/revamp1.pm line 68.
BEGIN not safe after errors--compilation aborted at 
template_stuff/revamp1.pm line 79.
Compilation failed in require at revamp1.pl line 6.
BEGIN failed--compilation aborted at revamp1.pl line 6.
$

What are my options?

Thanks for your comment,
-- 
Cal Dershowitz


------------------------------

Date: Fri, 11 Jul 2014 01:12:18 +0200
From: gamo <gamo@telecable.es>
Subject: Re: Keeping data and code separate in a module
Message-Id: <lpn6kk$58b$1@speranza.aioe.org>

El 11/07/14 00:25, Cal Dershowitz escribió:
> What are my options?

Try to export %config in its module

@EXPORT_OK = qw( %config );

otherwise you need to call the hash via something like config1::config,
which is unreadable.

-- 
http://www.telecable.es/personales/gamo/


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4248
***************************************


home help back first fref pref prev next nref lref last post