[28351] in Perl-Users-Digest
Perl-Users Digest, Issue: 9715 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 12 03:05:54 2006
Date: Tue, 12 Sep 2006 00:05:07 -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 Tue, 12 Sep 2006 Volume: 10 Number: 9715
Today's topics:
Re: (Off topic) Cyberwar question <skybuck2000@hotmail.com>
Re: Decode data of different charsets into UTF8 (Perl i <hjp-usenet2@hjp.at>
Re: How do you compress a url for ascii output? <shrike@cyberspace.org>
Re: How do you compress a url for ascii output? <hjp-usenet2@hjp.at>
Interface with Yahoo /MSN messenger using Perl <amit1976@gmail.com>
Re: localtime is now wrong after server change <jwcarlton@gmail.com>
Modifying and printing a string variable <offthedome@gmail.com>
new CPAN modules on Tue Sep 12 2006 (Randal Schwartz)
variable inheritance <mgarrish@gmail.com>
Re: variable inheritance <attn.steven.kuo@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Sep 2006 23:24:51 -0700
From: "Skybuck" <skybuck2000@hotmail.com>
Subject: Re: (Off topic) Cyberwar question
Message-Id: <1158042291.020552.55600@i42g2000cwa.googlegroups.com>
tuser schreef:
> > Michele Dondi wrote:
> > > On 4 Sep 2006 14:11:14 -0700, "Skybuck" <skybuck2000@hotmail.com>
> > > wrote:
> > >
> > > [loads ay shite]
> > >
> > > Oh ma perr wee lassie! Hud ah kent ye wir such a lurvely cunt ah
> > > wid've joined yir cyberwar n aw fir sure, likesay. Sae long...
>
> Skybuck wrote:
> > We need TRANSLATOR.
>
> use strict;
> use warnings;
>
> my $message =
> q{Oh ma perr wee lassie! Hud ah kent ye wir such a }.
> q{lurvely cunt ah wid've joined yir cyberwar n aw }.
> q{fir sure, likesay. Sae long...};
>
> my @translator =
> (83, 116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115,
> 117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33, 32, 83,
> 116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115, 117,
> 99, 104, 32, 97, 32, 98, 97, 98, 121, 33, 32, 83, 116, 111,
> 112, 32, 98, 101, 105, 110, 103, 32, 115, 117, 99, 104, 32,
> 97, 32, 98, 97, 98, 121, 33, 32, 83, 116, 111, 112, 32, 98,
> 101, 105, 110, 103, 32, 115, 117, 99, 104, 32, 97, 32, 98, 97,
> 98, 121, 33, 32, 83, 116, 111, 112, 32, 98, 101, 105, 110,
> 103, 32, 115, 117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33,
> 32, 83, 116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115,
> 117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33);
>
> my $p = 0;
> for (@translator) {
> substr($message, $p, 1) = chr $_;
> $p++;
> }
>
> print "translated message: $message\n";
Lol,
That's quite funny.
I actually believed:
"Stop being such a baby ! Stop being such a baby ! etc"
Was the real translation lol.
But then I was wondering how the fuck does the script work... I still
don't quite understand how the script work since I am not so good in
perl.. but I am not stupid you know !
You just simply made an array to substract the necessary values from
the text to turn it into the text you wish it to be... How long did you
spent time on that ? =D
Now I shall provide you what I think could be the real translation ;) !
:)
Original text:
> > > [loads ay shite]
> > >
> > > Oh ma perr wee lassie! Hud ah kent ye wir such a lurvely cunt ah
> > > wid've joined yir cyberwar n aw fir sure, likesay. Sae long...
Translated text:
[Loads a fart]
Oh my are we lazy ! He is searching a lovely cunt (or) Does somebody
know a lovely cunt ?
Ahhh, yeah right, like we would join his cyberwar. Like I said, So
lonnngg.
Bye,
Skybuck =D
------------------------------
Date: Tue, 12 Sep 2006 07:58:02 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Decode data of different charsets into UTF8 (Perl internal format)
Message-Id: <slrnegcj3h.v8k.hjp-usenet2@yoyo.hjp.at>
On 2006-09-11 09:08, ska <skg@mail.inf.fh-brs.de> wrote:
> Peter J. Holzer wrote:
>> On 2006-09-08 12:36, ska <skg@mail.inf.fh-brs.de> wrote:
>> > The text may be in CP437, Latin1, UTF8 or Unicode16 (latter except for
>> > the files). There is no way for me to get the charset from the
>> > "context".
>>
>> Are you sure Windows-1252 isn't in the mix, too?
>
> Well, I hope that Latin1 and Windows-1252 do match in all significant
> parts, they do as it concerned for the Umlauts & ß, at least per
> "recode".
Yup, but windows-1252 has additional characters between 0x80 and 0x9F,
so if you use the presence of these characters to detect cp437, you may
misidentify a windows-1252 file as cp437.
>> > if(Encode::is_utf8($line, 1)) {
>> > $charset = 'utf8';
>>
>> If is_utf8 is true, the data is already in perl's internal utf8 format,
>> and must not be decoded again.
>
> The "utf8" charset will skip the decoding part in the script.
Right. I shouldn't post before the first cup of coffee. Three places in
such a short script where I didn't understand what it was doing ...
>> Also, I think checking for the first character to be in range U+0001 to
>> U+00FF may be a bit too strict. What if the file starts with a Euro
>> sign?
>
> Fortunatly, I need not convert any text, but I can make guesses.
> (Otherwise I cannot differ cp437 from Latin1 at all).
iso-8859-1 and cp437 are easy as the ranges for accented characters
overlap very little. In fact the range where most accented characters
are in cp437 isn't even defined in iso-8859-1, so if you find a
character in this range it can't be iso-8859-1 (but it might be
win-1252).
> The first character of a file is most probably a plain ASCII
> character. Otherwise I couldn't detect Unicode16 that early -- well,
> in worst-case, there wouldn't be any single Latin1 character in it, so
> there would be no character less 256, hence, no single \0 in the data
> --> I wouldn't be able to detect Unicode16 at all.
I was assuming that you have texts (or text fragments) in some European
language, probably German by the choice of characters you probe for.
It's difficult to imagine a German text which doesn't contain at least
some latin-1 characters, but easy to image one which doesn't start with
a latin-1 character.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 11 Sep 2006 20:23:11 -0700
From: "shrike@cyberspace.org" <shrike@cyberspace.org>
Subject: Re: How do you compress a url for ascii output?
Message-Id: <1158031391.149568.38220@i42g2000cwa.googlegroups.com>
blaine@worldweb.com wrote:
> Hello,
>
> I've been trying to come up with a way to compress part of a url to
> make it shorter.
>
> Below I have an example of a variable for my url and want it smaller
> sized ascii. I've been trying the Compress:Zlib, however this doesn't
> output ascii.. Any ideas?
>
> use Compress::Zlib;
>
> #------ deflate -------
> my ($out, $out1, $status, $nout);
> my $x = deflateInit() or die "this text has been deflated/inflated";
>
> my $testStream =
> "CIAQEDEUDVvVEwEEChDtDaAVCHAhBFANADBeAlEqCvDrCgDHDeDyClBREgBSCFEdBIBbDeCYACBLEWAwEaEECMBjBvCEBiEbCCCgABEAElBNCsEYDFCODEEoECDaDgADCtEhBpAOCACGDECsCfBsCPAaBhAaDeDTECERBdEIBuEiEjDqCgEQBPDjBQAEEjDtDFCMDaDfAuCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC";
> ($out,$status) = $x->deflate($testStream);
>
> $status == Z_OK or die "deflation failed\n";
> ($out1, $status) = $x->flush();
>
> $out .= $out1;
>
>
> $status == Z_OK or die "deflation failed\n";
> print "deflated output: [$out]\n";
Any reason your not passing it as a form variable instead?
There is a module for sticking Storable's in HTML. You might take a
look at that. There is also a length limit difference between POST and
GET if I'm not mistaken.
Personally I compress, DES encrypt, Base32 encode and stick it in in
hidden form attribute. Of course that would crush the CPU if the site
ever got popular. But hey, CPU is cheap.
-Matt
------------------------------
Date: Tue, 12 Sep 2006 08:14:28 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How do you compress a url for ascii output?
Message-Id: <slrnegck2a.v8k.hjp-usenet2@yoyo.hjp.at>
On 2006-09-12 03:23, shrike@cyberspace.org <shrike@cyberspace.org> wrote:
> blaine@worldweb.com wrote:
>> I've been trying to come up with a way to compress part of a url to
>> make it shorter.
>>
>> Below I have an example of a variable for my url and want it smaller
>> sized ascii. I've been trying the Compress:Zlib, however this doesn't
>> output ascii.. Any ideas?
[...]
> Any reason your not passing it as a form variable instead?
What is a "form variable"? Forms can be submitted via GET or POST
requests. In a GET request, the variable becomes part of the URL, in a
POST request it is submitted as part of the body.
So you probably wanted to ask "Any reason not to use POST requests?"
There are a couple of reasons:
1) There is a semantic difference between GET and POST requests. GET
requests are supposed to only retrieve information from the server,
and not to change the server state. Hence they are cacheable and a
browser may automatically repeat them if the result is not in the
cache any more. A POST request is intended change the state of the
server. Hence the browser must sent every request exactly once to the
server.
2) POST requests are not bookmarkable.
3) Search engines don't issue POST requests.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 11 Sep 2006 23:37:52 -0700
From: "AD" <amit1976@gmail.com>
Subject: Interface with Yahoo /MSN messenger using Perl
Message-Id: <1158043072.543398.110490@h48g2000cwc.googlegroups.com>
Hi,
I tried following code for Yahoo Messenger
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new(
pre_login_url => 'http://edit.my.yahoo.co.in/config/',
hostname => 'scs.msg.yahoo.com',
);
$yahoo->id('adixit76');
$yahoo->password('musafir');
$yahoo->login or die "Can't login Yahoo!Messenger";
$yahoo->send('recipient_yahoo_id', 'Namaste!');
Everytime it says "Can't login Yahoo!Messenger"
Can anybody give me some idea?
------------------------------
Date: 11 Sep 2006 19:52:27 -0700
From: "Jason" <jwcarlton@gmail.com>
Subject: Re: localtime is now wrong after server change
Message-Id: <1158029547.380968.166590@e63g2000cwd.googlegroups.com>
Regarding the first two replies... I appreciate the help, but when did
everyone on this NG get to be so rude? Wow.
Anyone remember how we used to all be helpful and sharing, proclaiming
that the internet (and Perl) was designed for the free exchange of
ideas and information? We would have never called someone a whimpering
moron just for not understanding the purpose of a line of code. I guess
this is what we have to look forward to with the next generation.
<sarcasm>Yipee.</sarcasm>
> Here. you are adding one hour to the current time.
Thanks, and of course you're correct. I wrote that little bit of code
more than 8 years ago and have never needed to modify it, so it just
makes sense that I forgot why I did that. To answer the question of
"why didn't I change the time on the server," it's because (as I
mentioned in the original post) I was using a remote host, and didn't
have the ability to change their time zone.
> All of this is crazy stupid.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> sub timestamp {
> my ($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0 .. 5];
> sprintf(
> '%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d',
> $year + 1900, $mon + 1, $mday, $hour, $min, $sec,
> );
> }
>
> print timestamp(), "\n";
>
> __END__
>
> Or, just use POSIX::strftime as recommended.
Thank you for that. Now that I'm not in such a rush, I am spending time
going over my 8-year old program to make it a little faster and more
user friendly, and I'll definitely use your advice.
> Because you are adding one hour to the current time. How hard is that to
> figure out?
While working on old code, after having been awake for more than 48
hours... very hard! Be fair; if you weren't familiar with the logic,
what would make you think that 60*60 was equivalent to an hour?
> > though, because through WHM
>
> WTF is WHM?
That's the name of the server management program that I use. It goes
along with cPanel; WHM is used by the owner to manage the websites, and
cPanel is given to the users to maintain their own part of the server
with limited abilities. I figured you all were aware of it; WHM is
really the most common software for hosting companies to use.
- J
------------------------------
Date: 11 Sep 2006 23:31:09 -0700
From: "JC" <offthedome@gmail.com>
Subject: Modifying and printing a string variable
Message-Id: <1158042669.227067.74070@d34g2000cwd.googlegroups.com>
I have a hash, with key bodybgcolor pointing to a hexadecimal color
string "#FF9966". Problem is, I'm not allowed to pring the "#" sign, so
I need to print "FEDCBA". How do I do that?
------------------------------
Date: Tue, 12 Sep 2006 04:42:07 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Sep 12 2006
Message-Id: <J5GqE7.1v4w@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Apache-FakeCookie-0.08
http://search.cpan.org/~miker/Apache-FakeCookie-0.08/
fake request object for debugging
----
App-SimpleScan-Plugin-LinkCheck-1.03
http://search.cpan.org/~mcmahon/App-SimpleScan-Plugin-LinkCheck-1.03/
Link counting/presence/absence plugin
----
Bio-NEXUS-0.67
http://search.cpan.org/~tjhladish/Bio-NEXUS-0.67/
An object-oriented Perl Applications Programming Interface (API) for the NEXUS file format
----
CPAN-1.87_62
http://search.cpan.org/~andk/CPAN-1.87_62/
query, download and build perl modules from CPAN sites
----
Crypt-License-2.04
http://search.cpan.org/~miker/Crypt-License-2.04/
Perl extension to examine a license file.
----
DBIx-Std-v0.0.1
http://search.cpan.org/~dmuey/DBIx-Std-v0.0.1/
Placeholder while its written
----
Data-Password-Manager-0.02
http://search.cpan.org/~miker/Data-Password-Manager-0.02/
generate, check, manage crypt - des passwords
----
Date-Holidays-0.08
http://search.cpan.org/~jonasbn/Date-Holidays-0.08/
a Date::Holidays::* OOP wrapper
----
ExtUtils-MakeMaker-6.30_04
http://search.cpan.org/~mschwern/ExtUtils-MakeMaker-6.30_04/
Create a module Makefile
----
Games-Sudoku-SudokuTk-0.05
http://search.cpan.org/~cguine/Games-Sudoku-SudokuTk-0.05/
Perl extension for Sudoku with Tk
----
Geo-CountryFlags-0.03
http://search.cpan.org/~miker/Geo-CountryFlags-0.03/
methods to fetch flag gif's
----
HTML-LinkList-0.13
http://search.cpan.org/~rubykat/HTML-LinkList-0.13/
Create a 'smart' list of HTML links.
----
HTML-Widgets-NavMenu-1.0001
http://search.cpan.org/~shlomif/HTML-Widgets-NavMenu-1.0001/
A Perl Module for Generating HTML Navigation Menus
----
IPTables-IPv4-DBTarpit-0.36
http://search.cpan.org/~miker/IPTables-IPv4-DBTarpit-0.36/
----
Logfile-EPrints-1.08
http://search.cpan.org/~timbrody/Logfile-EPrints-1.08/
Parse Apache logs from GNU EPrints
----
Mail-SMTP-Honeypot-0.05
http://search.cpan.org/~miker/Mail-SMTP-Honeypot-0.05/
Dummy mail server
----
Mail-SpamCannibal-0.74
http://search.cpan.org/~miker/Mail-SpamCannibal-0.74/
A tool to stop SPAM
----
Net-DNSBL-MultiDaemon-0.18
http://search.cpan.org/~miker/Net-DNSBL-MultiDaemon-0.18/
multi DNSBL prioritization
----
Net-RawIP-0.21_02
http://search.cpan.org/~szabgab/Net-RawIP-0.21_02/
Perl extension for manipulate raw ip packets with interface to libpcap
----
Net-eBay-0.37
http://search.cpan.org/~ichudov/Net-eBay-0.37/
Perl Interface to XML based eBay API.
----
OpenOffice-OODoc-2.028
http://search.cpan.org/~jmgdoc/OpenOffice-OODoc-2.028/
The Perl Open OpenDocument Connector
----
POE-Component-Client-NNTP-1.03
http://search.cpan.org/~bingos/POE-Component-Client-NNTP-1.03/
A component that provides access to NNTP.
----
POE-Declare-0.01
http://search.cpan.org/~adamk/POE-Declare-0.01/
A POE abstraction layer for conciseness and simplicity
----
Perl-Critic-0.2
http://search.cpan.org/~thaljef/Perl-Critic-0.2/
Critique Perl source code for best-practices
----
Pod-Perldoc-ToToc-1.03
http://search.cpan.org/~bdfoy/Pod-Perldoc-ToToc-1.03/
This is the description
----
Proc-PidUtil-0.08
http://search.cpan.org/~miker/Proc-PidUtil-0.08/
PID file management utilities
----
SQLite-Work-0.09
http://search.cpan.org/~rubykat/SQLite-Work-0.09/
report on and update an SQLite database.
----
Shell-EnvImporter-1.03
http://search.cpan.org/~dfaraldo/Shell-EnvImporter-1.03/
Perl extension for importing environment variable changes from external commands or shell scripts
----
Spreadsheet-ParseExcel-0.27_01
http://search.cpan.org/~szabgab/Spreadsheet-ParseExcel-0.27_01/
Get information from Excel file
----
Template-PopupTreeSelect-0.9
http://search.cpan.org/~jonas/Template-PopupTreeSelect-0.9/
HTML popup tree widget
----
Text-Password-Pronouncable.pm-0.25
http://search.cpan.org/~clkao/Text-Password-Pronouncable.pm-0.25/
----
WWW-RobotRules-MySQLCache-0.02
http://search.cpan.org/~apatwa/WWW-RobotRules-MySQLCache-0.02/
Perl extension for maintaining a robots.txt in a MySQL database
----
Web-Scaffold-0.05
http://search.cpan.org/~miker/Web-Scaffold-0.05/
build minimalist fancy web sites
----
WebService-YouTube-0.03
http://search.cpan.org/~yoshida/WebService-YouTube-0.03/
Perl interfece to YouTube
----
WebService-YouTube-0.04
http://search.cpan.org/~yoshida/WebService-YouTube-0.04/
Perl interfece to YouTube
----
ack-1.28
http://search.cpan.org/~petdance/ack-1.28/
grep-like text finder for large trees of text
----
iCal-Parser-1.13
http://search.cpan.org/~rfrankel/iCal-Parser-1.13/
Parse iCalendar files into a data structure
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 11 Sep 2006 17:11:21 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: variable inheritance
Message-Id: <1158019881.167531.279220@d34g2000cwd.googlegroups.com>
I'm faced with the problem of one module serving up data for 10
different applications, where the only difference is the data being
generated. Without going into the gory details, each year the data
structure (the database) can change for each application and the
applications have no relation to each other.
For this reason, I've set up 10 separate modules each defining the same
set of variables so that my generic class can access the configuration
information without needing to know which application it is dealing
with. Some of the data is the same between applications, so I keep that
in the base class and then the subclasses override the variables that
are specific to each of the children. As I'm sure the above must sound
like gibberish, take for example:
### DataBase.pm
package DataBase;
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo %someOtherConfig/;
# this variable will get overriden by the child module
# but declaring it here means I can use it in the
# module and avoid problems with strictures
# not finding the variable before the child require
our %appInfo;
our %someOtherConfig = (test => 1);
### Child1.pm
package DataBase::Child1;
use base 'DataBase';
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo/;
our %appInfo = (table1 => 'col1, col2, col3');
### application
use strict;
use warnings;
use DataBase;
my $test = 1;
if ($test == 1) {
require DataBase::Child1;
import DataBase::Child1;
}
print keys %appInfo;
#########
The above will print the correct 'table1' key, but my question is am I
setting myself up for disaster if I actually try and go this route? I'm
not saying it's the most elegant code, but since it's not a true object
that I want but more of a configuration file is there any danger in my
assumption that the require will properly result in the %appInfo being
the child version.
I currently have the data all in one big configuration file but it's
quickly becoming unwieldy and too large for the web application it's
designed to serve (plus causes other limitations I won't go into by
sharing so much of the same data), so I want to isolate and import only
as little data as necessary to get the job done.
Matt
------------------------------
Date: 11 Sep 2006 18:36:36 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: variable inheritance
Message-Id: <1158024996.828679.105070@i3g2000cwc.googlegroups.com>
Matt Garrish wrote:
> I'm faced with the problem of one module serving up data for 10
> different applications, where the only difference is the data being
> generated. Without going into the gory details, each year the data
> structure (the database) can change for each application and the
> applications have no relation to each other.
>
> For this reason, I've set up 10 separate modules each defining the same
> set of variables so that my generic class can access the configuration
> information without needing to know which application it is dealing
> with. Some of the data is the same between applications, so I keep that
> in the base class and then the subclasses override the variables that
> are specific to each of the children. As I'm sure the above must sound
> like gibberish, take for example:
>
> ### DataBase.pm
>
> package DataBase;
>
> use Exporter;
> @ISA = qw/Exporter/;
> @EXPORT = qw/%appInfo %someOtherConfig/;
>
> # this variable will get overriden by the child module
> # but declaring it here means I can use it in the
> # module and avoid problems with strictures
> # not finding the variable before the child require
> our %appInfo;
>
> our %someOtherConfig = (test => 1);
>
I don't see how the %appInfo has in this package
gets over-writtten.
> ### Child1.pm
>
> package DataBase::Child1;
>
> use base 'DataBase';
>
> use Exporter;
> @ISA = qw/Exporter/;
> @EXPORT = qw/%appInfo/;
>
> our %appInfo = (table1 => 'col1, col2, col3');
>
>
> ### application
>
> use strict;
> use warnings;
>
> use DataBase;
>
> my $test = 1;
>
> if ($test == 1) {
> require DataBase::Child1;
> import DataBase::Child1;
> }
>
> print keys %appInfo;
>
>
> #########
>
> The above will print the correct 'table1' key, but my question is am I
> setting myself up for disaster if I actually try and go this route? I'm
> not saying it's the most elegant code, but since it's not a true object
> that I want but more of a configuration file is there any danger in my
> assumption that the require will properly result in the %appInfo being
> the child version.
Well, it's confusing to say the least. Are you expecting the %appInfo
in package DataBase to contain the same information as the %appInfo
in package main?
With a bit of code added for debugging and introspection, you'll see
that they aren't the same:
=== file 1 ===
package DataBase;
use Exporter;
use Data::Dumper;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo %someOtherConfig/;
our %appInfo;
our %someOtherConfig = ( test => 1 );
use strict;
use warnings;
sub dump
{
print Dumper \%appInfo;
}
1;
=== file 2 ===
package DataBase::Child1;
use base 'DataBase';
use Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo/;
use Data::Dumper;
our %appInfo = ( table1 => 'col1, col2, col3');
sub dump
{
print Dumper \@ISA;
}
1;
=== file 3 ===
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
BEGIN { $Exporter::Verbose = 1 };
use DataBase;
require DataBase::Child1;
import DataBase::Child1;
print Dumper \%appInfo;
DataBase->dump;
DataBase::Child1->dump;
=== output ===
Carp::EXPORT_FAIL cached: verbose &verbose at
/usr/local/perl-5.8.7/lib/5.8.7/Exporter/Heavy.pm line 171.
Importing into Carp from Carp: carp, confess, croak at
/usr/local/perl-5.8.7/lib/5.8.7/Exporter/Heavy.pm line 190.
Importing into DataBase from Exporter: at DataBase.pm line 3
Importing into DataBase from Data::Dumper: Dumper at DataBase.pm line 4
Importing into main from DataBase: %appInfo, %someOtherConfig at app.pl
line 7
main::BEGIN() called at DataBase.pm line 7
eval {...} called at DataBase.pm line 7
Importing into DataBase::Child1 from Exporter: at DataBase/Child1.pm
line 4
DataBase::Child1::BEGIN() called at DataBase/Child1.pm line 4
eval {...} called at DataBase/Child1.pm line 4
require DataBase/Child1.pm called at app.pl line 9
Importing into DataBase::Child1 from Data::Dumper: Dumper at
DataBase/Child1.pm line 7
DataBase::Child1::BEGIN() called at DataBase/Child1.pm line 7
eval {...} called at DataBase/Child1.pm line 7
require DataBase/Child1.pm called at app.pl line 9
Importing into main from DataBase::Child1: %appInfo at app.pl line 10
$VAR1 = {
'table1' => 'col1, col2, col3'
};
$VAR1 = {};
$VAR1 = [
'Exporter'
];
Note that the %appInfo hash in DataBase remains empty.
Also note that the @ISA array in DataBase::Child1 only contains
exporter -- it's not a derived class of DataBase; you've wiped
out the inheritance by reassigning to @ISA.
Perhaps if you showed more of your code, then we could make
a more informed recommendation. What do the subroutines
in DataBase do with %appInfo, for example?
Perhaps you can experiment with having your own
import function and the export_to_level function from Exporter?
Here's an example:
=== file 1 ===
package DataBase;
use Exporter;
use Data::Dumper;
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo %someOtherConfig/;
our %appInfo;
our %someOtherConfig = ( test => 1 );
sub import {
my $level = shift;
my $child = __PACKAGE__ . "::" . shift;
eval "require $child";
die $@ if $@;
$child->import;
__PACKAGE__->export_to_level(1, $level, @EXPORT);
}
use strict;
use warnings;
sub dump
{
print Dumper \%appInfo;
}
1;
=== file 2 ===
package DataBase::Child1;
use Exporter;
BEGIN {
@ISA = qw/Exporter/;
@EXPORT = qw/%appInfo/;
};
use base 'DataBase';
use Data::Dumper;
our %appInfo = ( table1 => 'col1, col2, col3');
sub dump
{
print Dumper \@ISA;
}
1;
=== file 3 ===
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
BEGIN { $Exporter::Verbose = 1 };
use DataBase ('Child1');
print Dumper \%appInfo;
DataBase->dump;
DataBase::Child1->dump;
=== output ===
...
$VAR1 = {
'table1' => 'col1, col2, col3'
};
$VAR1 = {
'table1' => 'col1, col2, col3'
};
$VAR1 = [
'Exporter',
'DataBase'
];
--
Hope this helps,
Steven
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 9715
***************************************