[28354] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9718 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 12 18:05:58 2006

Date: Tue, 12 Sep 2006 15:05:09 -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: 9718

Today's topics:
        converting php md5 function to perl checarsner@gmail.com
    Re: converting php md5 function to perl <sbryce@scottbryce.com>
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? xhoster@gmail.com
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? <bik.mido@tiscalinet.it>
    Re: Hash slice from a hash reference? <bik.mido@tiscalinet.it>
        Help with the last element in an array <pradeep.bg@gmail.com>
    Re: Help with the last element in an array <someone@example.com>
    Re: Help with the last element in an array <pradeep.bg@gmail.com>
    Re: Help with the last element in an array <someone@example.com>
    Re: Help with the last element in an array <pradeep.bg@gmail.com>
    Re: I want to output all of my STDOUT to a single line. <bik.mido@tiscalinet.it>
    Re: Keeping changes to %ENV in Win32 process <bik.mido@tiscalinet.it>
        NTLM and LWP::UserAgent <mumebuhi@gmail.com>
    Re: NTLM and LWP::UserAgent <mumebuhi@gmail.com>
    Re: Parsing strings and obeying quotes <rvtol+news@isolution.nl>
    Re: Search and replace problem ironmanda@yahoo.com
    Re: variable inheritance <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: variable inheritance <mgarrish@gmail.com>
    Re: variable inheritance <mgarrish@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Sep 2006 13:16:39 -0700
From: checarsner@gmail.com
Subject: converting php md5 function to perl
Message-Id: <1158092199.849372.326210@e3g2000cwe.googlegroups.com>

Hey all

how I can convert the PHP password encryption  into a Perl function
which generates the same result...
I am completely stuck at this point... My PHP knowledge is close to
zero. I understand their procedure but when I do it in Perl it comes
back with a different result...
in PHP: $newPw["userPassword"] = '{md5}' .
base64_encode(pack('H*',md5($newPasswd)));
sorry the help file is a place where we deffinitly will not find
anything..
the problem is not, understanding what the PHP code is doing. The issue
is to make Perl do the same.

TIA

Che



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

Date: Tue, 12 Sep 2006 15:48:45 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: converting php md5 function to perl
Message-Id: <WMmdne8BfLWhtprYnZ2dnUVZ_tidnZ2d@comcast.com>

checarsner@gmail.com wrote:

> how I can convert the PHP password encryption  into a Perl function 
> which generates the same result...

I'd start here:

http://search.cpan.org/~gaas/Digest-MD5-2.36/MD5.pm


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

Date: 12 Sep 2006 20:14:25 GMT
From: xhoster@gmail.com
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <20060912161514.883$Ln@newsreader.com>

"it_says_BALLS_on_your forehead" <simon.chao@fmr.com> wrote:
> brian d foy wrote:
> > In article <1158068446.174221.266380@e63g2000cwd.googlegroups.com>,
> > it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote:
> >
> > > PerlFAQ Server wrote:
> >
> > > > -------------------------------------------------------------------
> > > > -
> >
> > > > 9.7: How do I make a pop-up menu in HTML?
> >
> > > Is this really On Topic?
> >
> > As a frequently asked question about Perl, it got an entry in perlfaq9.
> > You'll find lots of CGI questions and answers in there.
>
> Ok, I was just concerned that this would be viewed as a hole through
> which any one could ask any HTML question to this newsgroup and have
> that question be considered On Topic.

I think the FAQ should be there (because it is frequenctly asked about
Perl, even if it shouldn't be.  Or at least things like it are frequently
asked about Perl, if that exact question is not) but the answer should
include a opening phrase like "This is an HTML question, not a Perl
question.  However..." And maybe copy the line from perldoc -q 500,
"Questions that appear to be Perl questions but are really CGI[/HTML] ones
that are posted to comp.lang.perl.misc are not so well received."

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 12 Sep 2006 22:44:31 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <9s2eg2t703b7262vd1dsoiptbntja2e8b2@4ax.com>

On 12 Sep 2006 09:53:41 -0700, "it_says_BALLS_on_your forehead"
<simon.chao@fmr.com> wrote:

>Ok, I was just concerned that this would be viewed as a hole through
>which any one could ask any HTML question to this newsgroup and have
>that question be considered On Topic.

I do not share your concern because in practice chances are high that
those who are familiar with the faq *do* know that the question is not
strictly a Perl one. Even considering the interaction between the
regular postings of the FAQ to the group and the group itself, the
risk does not seem that high. Indeed one who will ask that kind of
question typically won't even take care of checking if something
similar has been asked before. But then... see also below!

>Many times I have seen people ask HTML questions, with the response
>from the regulars being that those questions are Off Topic.

HTML questions, not to say webserver configuration ones!

>This FAQ (in my mind, at least), legitimizes some of those queries. A
>change in the verbiage of the Subject to include a reference to the
>CGI.pm would mitigate this (somewhat). Just my $0.02.

Even though I do not share your concern and even though I am aware
that apart from one coincidental particular (namely, that at least one
of the faq mainteiners is also an active member of the group) the
group and the faq do not have a mutual relationship, I find it somehow
incoherent that people rightly warns newbies that their question is OT
and that the faq just answers the question even if it is.

What's wrong it's not that the faq answers this particular question:
since it does have a Perl-related answer, if asked in a Perl-related
context, it deserves one. In fact people would typically warn about
the OT, and then answer it.

In view of all this, changing the Subject to the effect of including a
reference to CGI.pm would not be much of a solution, since typically
one who already knows what it is or even has a vague idea has smaller
chances of actually asking the question. Rather, a remark that the
question is not strictly on topic and a reminder that for quite about
anything related to web editing CGI.pm is the way to go, would fit
nicely.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 12 Sep 2006 20:59:21 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Hash slice from a hash reference?
Message-Id: <mjmdg2hmch77bm16u7lq908kldq2t76m1a@4ax.com>

On 11 Sep 2006 12:44:21 -0700, "alt.binaries.pictures.numismatics"
<roblund@gmail.com> wrote:

>Slightly off topic, but in general, I think that hash slices make for
>"unreadable" code.   Sure, many of us know how to use them, and can
>recognize them at the same time, but many many perl programmers really
>have no idea how they work, and are utterly baffled by the syntax.

call me elitist if you like, but IMHO a *perl programmer* must be
confident with at least language basic constructs. Otherwise I'd call
him/her "a coder who occasionally reads or writes some perl code, and
probably poor one". I can't limit the expressive power of the language
I'm using for the benefit of someone who will possibly maintaining my
code without being a perl programmer. Granted, I'm *not* advocating
extreme conciseness, let alone obfu, in production code: I'm
advocating code that will be clear to the average *perl programmer*.

>Especially in the case of two or three keys, it might be wiser to just
>explicity assign the elements:
>
>$hash->{key01} = 'val01';
>$hash->{key02} = 'val02';

I second that, depending on the case. It depends on the emphasis I may
want to impose to the single assignments. But hardly with more than
two keys...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 12 Sep 2006 11:54:10 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Help with the last element in an array
Message-Id: <1158087250.378580.251720@h48g2000cwc.googlegroups.com>

Hi All,

I have a file like: (test1)

SA	blk: 2 pg: 4 col: 5 time: 4
SB	blk: 4 pg: 4 col: 6 time: 4
SC	blk: 5 pg: 3 col: 3 time: 2
SD	blk: 1 pg: 2 col: 8 time: 9
SE	blk: 8 pg: 0 col: 3 time: 10
SF	blk: 2 pg: 1 col: 6 time: 11
SG	blk: 5 pg: 9 col: 0 time: 45

I am trying to generate the output:

SA - SB - SC
SB - SC - SD
SC - SD - SE
SD - SE - SF
SE - SF - SG

But i am getting:

SA - SB - SC
SB - SC - SD
SC - SD - SE
SD - SE - SF

Here i am missing out the last SE - SF - SG.

The array in the code below (@seen) has SE - SF and SF - SG. I need to
combine these and delete SF to get SE - SF - SG. Can somebody please
give me some ideas on it.

The code i am using is:

#!/usr/bin/perl

open (FILE, "test1") || die;

while (<FILE>) {
    chomp;
    push (@array, $_);
    #print "@array\n";
  }
    $elements = $#array;

    for my $i (0 .. $elements) {
      my $line = $array[$i];
      #print $line;

      if (($line !~
/^\s*(\S+)\t+blk:\s+(\S+)\s+pg:\s+(\S+)\s+col:\s+(\S+)\s+time:\s+(\S+)/)){
	print "Bad line:$line\n";
      }

     if (@prev) {
      my $stKey = "$prev[1]-$1";
      #print "######$stKey######\n";
      threeState($stKey);
    }
    @prev = ($line, $1);

  }
    close (FILE);

my @seen =();

sub threeState($)
{
 my $state = $_[0];
 print "$_[0]\n";

 if (@seen < 2) {
  push (@seen, $state);
  print "#!#!#!#!#!!#!#!@seen#!#!#!#!#!#!\n";
} else {
  my $key=join '-',@seen;
  @test = split(/-/,$key);
  splice (@test,1,1);
  my $key=join '-',@test;
  print
"########################################################$key\n";
  if ($covValidAA{"$key"}) {
    $covSTCntAA{"$key"}++;
    #print "$stKey $covSTCntAA{$stKey}\n";
  } else {
    if (~$covValidAA{"$key"}) {
	  $covSTCntAA{"$key"}--;
	}
  }
  shift @seen;
  push (@seen,$state);
  print "@seen\n";
}

}


Thanks for your time.



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

Date: Tue, 12 Sep 2006 20:09:19 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with the last element in an array
Message-Id: <PtENg.3293$cz3.735@edtnps82>

Deepu wrote:
> 
> I have a file like: (test1)
> 
> SA	blk: 2 pg: 4 col: 5 time: 4
> SB	blk: 4 pg: 4 col: 6 time: 4
> SC	blk: 5 pg: 3 col: 3 time: 2
> SD	blk: 1 pg: 2 col: 8 time: 9
> SE	blk: 8 pg: 0 col: 3 time: 10
> SF	blk: 2 pg: 1 col: 6 time: 11
> SG	blk: 5 pg: 9 col: 0 time: 45
> 
> I am trying to generate the output:
> 
> SA - SB - SC
> SB - SC - SD
> SC - SD - SE
> SD - SE - SF
> SE - SF - SG
> 
> But i am getting:
> 
> SA - SB - SC
> SB - SC - SD
> SC - SD - SE
> SD - SE - SF
> 
> Here i am missing out the last SE - SF - SG.
> 
> The array in the code below (@seen) has SE - SF and SF - SG. I need to
> combine these and delete SF to get SE - SF - SG. Can somebody please
> give me some ideas on it.

You probably want something like:

#!/usr/bin/perl
use warnings;
use strict;

open FILE, '<', 'test1' die "Cannot open 'test1' $!";

my @array;
while ( <FILE> ) {
    print "Bad line:$_" unless
/^\s*(\S+)\t+blk:\s+\S+\s+pg:\s+\S+\s+col:\s+\S+\s+time:\s+\S+/;
    push @array, $1;
    }
close FILE;

while ( @array >= 4 ) {
    print join( ' - ', @array[ 0 .. 3 ] ), "\n";
    shift @array;
    }

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 12 Sep 2006 13:19:54 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Re: Help with the last element in an array
Message-Id: <1158092394.824441.20910@e3g2000cwe.googlegroups.com>

Hi John,

Thanks for the help. I tried the code specified by you but now i
missing out the first transition SA - SB - SC. How can this be
corrected.


 #!/usr/bin/perl
 use warnings;
 use strict;

 open FILE, '<', 'test1' die "Cannot open 'test1' $!";

 my @array;
 while ( <FILE> ) {
     print "Bad line:$_" unless
 /^\s*(\S+)\t+blk:\s+\S+\s+pg:\s+\S+\s+col:\s+\S+\s+time:\s+\S+/;
     push @array, $1;
     }
 close FILE;

 while ( @array >= 4 ) {
     print join( ' - ', @array[ 0 .. 3 ] ), "\n";
     shift @array;
     }
 
 __END__


 Thanks for the help.



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

Date: Tue, 12 Sep 2006 20:29:25 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Help with the last element in an array
Message-Id: <FMENg.2915$KA6.358@clgrps12>

Deepu wrote:
> Hi John,
> 
> Thanks for the help. I tried the code specified by you but now i
> missing out the first transition SA - SB - SC. How can this be
> corrected.

I don't know what to tell you, it works fine for me.


John
-- 
use Perl;
program
fulfillment


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

Date: 12 Sep 2006 13:35:22 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Re: Help with the last element in an array
Message-Id: <1158093322.825561.193920@d34g2000cwd.googlegroups.com>


> I don't know what to tell you, it works fine for me.

I am extremely sorry, actually the code works fine. It was my mistake.
Thanks for the help.

- Deepu



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

Date: 12 Sep 2006 20:59:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: I want to output all of my STDOUT to a single line....dont want to scroll
Message-Id: <cdndg2596acl2vq3h08cvp3o0mstgle4m1@4ax.com>

On 11 Sep 2006 13:17:01 -0700, seancsnyder@gmail.com wrote:

>what does this do?
>
>   $| = 1; # output autoflush mode

Autoflushes output.

>David Squire wrote:
[snip full quoted post]

*PLEASE* Do not top-post!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 12 Sep 2006 20:59:23 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Keeping changes to %ENV in Win32 process
Message-Id: <thndg2l9d4mohgsq17cmsj1fkidbgunv7i@4ax.com>

On 12 Sep 2006 02:43:31 -0700, "jeffeld" <eldridge.jeff@gmail.com>
wrote:

>$ENV{JEFF}="FOO";
>
>and then in a Win32 .cmd file
>
>perl jeff.pl
>echo %JEFF%
>
>Is this possible? If not, what would be a better way to return a simple

Possible, and expected. See

  perldoc -q environment

*Maybe*, under Windows it may actually be possible to that
(permanently modifying the environment) by fiddling with the registry.

>status to the command shell for processing after the script has ended.

Scripts... well, programs, *do* return their status to the shell. Just
use exit().


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 12 Sep 2006 14:42:24 -0700
From: "mumebuhi" <mumebuhi@gmail.com>
Subject: NTLM and LWP::UserAgent
Message-Id: <1158097344.905112.248970@d34g2000cwd.googlegroups.com>

I am having problems accessing any sites outside my organization using
LWP::UserAgent. My organization is using NTLM authentication.

My code looks like the following (similar to the one explained in
http://search.cpan.org/dist/libwww-perl/lib/LWP/Authen/Ntlm.pm).

# --- start ---
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::Debug qw(+);

my $url = 'http://www.google.com';

my $ua = LWP::UserAgent->new(keep_alive => 1);
$ua->credentials('host:8080', '', 'username', 'password');
$request = new HTTP::Request GET => $url;
$response = $ua->request($request);
print $response->code . "\n";
# --- end ---

The output is
LWP::UserAgent::new: ()
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: GET http://www.google.com
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 624 bytes
LWP::UserAgent::request: Simple response: Found
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: GET
http://bcauth/?cfru=aHR0cDovL3d3dy5nb29nbGUuY29tLw==
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 744 bytes
LWP::Protocol::collect: read 66 bytes
LWP::UserAgent::request: Simple response: Unauthorized
401

Help?



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

Date: 12 Sep 2006 14:45:27 -0700
From: "mumebuhi" <mumebuhi@gmail.com>
Subject: Re: NTLM and LWP::UserAgent
Message-Id: <1158097527.493893.64990@i3g2000cwc.googlegroups.com>

I have several topics that discuss similar problem. However, I
unfortunately still can not my problem. I hope somebody can help.
Thanks.


Buhi



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

Date: Tue, 12 Sep 2006 22:50:25 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Parsing strings and obeying quotes
Message-Id: <ee7dll.1ac.1@news.isolution.nl>

Mia schreef:

> I'm trying to parse a string into an array of words or phrases,
> something like:
>
> my $string = "abc def ghi";
> my @words = split(/ /,$string);
>
> ...but I also want to handle the case where there are quoted phrases
> within the string, i.e.:
>
> my $string = 'abc "def ghi"';
> or
> my $string = "abc 'def ghi'";
>
> I want to preserve the quoted phrase as one element.  Such a simple
> thing, one would think, but I've not found a technique yet.
>
> Anyone have a hint for me?

Think up complexer strings.

  "Dungit," he said, "I left my "o'lang syne" at the baker's."

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 12 Sep 2006 12:00:10 -0700
From: ironmanda@yahoo.com
Subject: Re: Search and replace problem
Message-Id: <1158087609.929880.226250@b28g2000cwb.googlegroups.com>

Thanks John, this worked.  They was the /eeg on
the search and replace.  Much appreciated.

David

John W. Krahn wrote:
> ironmanda@yahoo.com wrote:
> > I'm trying to build a general way of handling search and replace
> > of strings.  The regexp in the commented out part works perfectly.
> > But, the foreach part doesn't work.  The thing is, \1 is being
> > interpreted literally.  Any ideas?
> >
> >
> > #!/usr/local/bin/perl
> >
> > my $str="http://www.xxx.com/yyy/zzz/25331/2";
> >
> > $repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";
> >
> > # $str=~s/([0-9]*)\/[0-9]+$/\1/g;
> > # print "$str\n";
> > # exit 0;
> >
> > foreach $key (sort keys %repurl) {
> >     print "$key - $repurl{$key}\n";
> >     $str=~s/$key/$repurl{$key}/g;
> > }
> >
> > print "$str\n";
>
> $ perl -Mwarnings -Mstrict -e'
> my $str = q[http://www.xxx.com/yyy/zzz/25331/2];
>
> my %repurl = ( q[(\d*)/\d+$] => q[$1] );
>
> for my $key ( sort keys %repurl ) {
>     print "$key - $repurl{$key}\n";
>     $str =~ s/$key/$repurl{$key}/eeg;
>     print "$str\n";
> }
> '
> (\d*)/\d+$ - $1
> http://www.xxx.com/yyy/zzz/25331
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment



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

Date: Tue, 12 Sep 2006 18:26:18 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: variable inheritance
Message-Id: <eZCNg.10574$bM.6062@newsread4.news.pas.earthlink.net>

On 09/12/2006 05:56 AM, Matt Garrish wrote:
> [ problem with inheriting class data snipped ]
> The problem in a nutshell is how do I make the variable "exist" in the 
> eyes of strictures but not know what it contains until the require 
> happens. I was trying to come up with any trickery I could just in the 
> interests of seeing what else was possible, but I think I'll just go 
> back to tried and true.
> 
> Matt
> 

IIWY I would use Class::Data::Inheritable and re-write the 
application code to use the class data accessors.


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

Date: 12 Sep 2006 13:43:56 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: variable inheritance
Message-Id: <1158093836.807334.256250@h48g2000cwc.googlegroups.com>


Uri Guttman wrote:

> >>>>> "MG" == Matt Garrish <mgarrish@gmail.com> writes:
>
>   MG> The problem in a nutshell is how do I make the variable "exist" in the
>   MG> eyes of strictures but not know what it contains until the require
>   MG> happens. I was trying to come up with any trickery I could just in the
>   MG> interests of seeing what else was possible, but I think I'll just go
>   MG> back to tried and true.
>
> as we tell others when they do a config with tons of scalars:
>
> 	use a hash.
>

The data is currently in hashes, actually, but there are about fifteeen
in all dealing with various other issues. It's essentially a table
generator module that doesn't want to know anything specific about the
tables but just render them according to the information you pass in.
Unlike a straight database dump to html, however, it's configurable for
external links, cross-references, footnotes, etc. All of this
information has been abstracted out of the class and into the
configuration file, but invariably the usefulness of the module has
grown as so the scale of it has grown beyond its original conception.
I'm now working at redesigning the config data to better scale with the
application.

Unfortunately my brain has also been reduced to mush in the process,
and things that should seem obvious to me no longer are.

> then you can declare it with our %config in each of the required files
> (assuming they are all in the same name space). in each file you just
> execute a set of assignments (or a large slice assignment) to the config
> hash. you can even have a my hash in the file and assign it with a slice
> to the main config
>

And that's what wasn't jumping out at me. For whatever reason I got it
in my head to just declare it once in the parent so that it would be
visible at compile time to the calling module and then "overwrite" it
in the require. Thanks helping me screw my head back on.

Matt



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

Date: 12 Sep 2006 14:02:55 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: variable inheritance
Message-Id: <1158094975.570545.31350@d34g2000cwd.googlegroups.com>


xhoster@gmail.com wrote:

> "Matt Garrish" <mgarrish@gmail.com> 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.
>
> If the data can change independently, the structure of the data can change
> independently, and the applications have no relation to each other, then
> why even bother trying to tie them together?
>

Why not? The output is identical, only the structure and data differs,
and even at that only to degrees. Since the final output is identical
and only the data coming in different it would be silly to write 10
different applications that all do the same thing. Unless you like the
copy/paste approach to programming.

> > 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,
>
> Just by accident?  Does this shared data change frequently?  When it does
> change, is it highly likely to change in concert across all apps?  If
> either of these are "no" then it seems like it would be better just to copy
> this data into each of 10 independent modules.
>

Why would I partition off the data between what is general across all
and what is specific to each if that weren't the case? I'm not inclined
to go into ten (and growing) modules to update information that is
shared across them all. The point is that the parent gets imported
regardless of which child gets required later. As one way of making the
data structure appear to be present when the code is compiled, I was
toying with placing blank structures in the parent and overwriting them
in the child.

> ...
> > 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.
>
> That seems to be correct, in the main package (or whichever package
> executed the require).  Not for other packages, however.
>

I realize that, but that's not a concern. There is only one module that
imports this configuration data, so I don't need it to be available
anywhere else.

> > I currently have the data all in one big configuration file but it's
> > quickly becoming unwieldy and too large
>
> What does that mean?  It is taking too long to parse?  It is taxing your
> server memory?  It is causing your text editor to crash when you try to
> edit it?  It is taxing you mental ability to understand it all?
>

You do know that sarcasm is about as funny and original as going around
telling everyone to "tell it to the hand", right? But whatever gets you
off. If you've dealt with a program of any complexity before, you'd
understand exactly what that means. The data wasn't ever intended or
expected to grow at the rate it is now, so what was a manageable
configuration file at first and designed for the scale of the project
is now causing data conflicts. The approach to keep the file in its
orginal state is to start nesting the data within new structures and
rewriting all of the application code that handles it, or parse it down
so that it appears as though no change has been made because each
application has it's own data in its own config module (exactly as it
was originally designed).

Matt



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

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 9718
***************************************


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