[26195] in Perl-Users-Digest
Perl-Users Digest, Issue: 8384 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 2 14:05:24 2005
Date: Fri, 2 Sep 2005 11:05: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 Fri, 2 Sep 2005 Volume: 10 Number: 8384
Today's topics:
Re: Can a Perl Programmer Pick up PHP quickly? axel@white-eagle.invalid.uk
Re: Can a Perl Programmer Pick up PHP quickly? <perl@my-header.org>
Re: Disappearing Module (Anno Siegel)
Re: Unexpected array behaviour <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Re: Unexpected array behaviour <tadmc@augustmail.com>
Re: values of hash of hash <perl@my-header.org>
Re: What is the better method for using hash?? xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Sep 2005 16:59:24 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <Mx%Re.911$pm2.245@fe3.news.blueyonder.co.uk>
John Bokma <john@castleamber.com> wrote:
> Average_Joe <joe@pong.tunestar.net> wrote:
>> You can probably pick up PHP just by sitting down with it for an
>> evening.
> *sniggers* Only if you have little understanding of Perl and little
> understanding of PHP is required.
It really depends on what you want to do with it. If it just a
question of picking up some data from a database and displaying it
on a website, then it is very straight forward.
I cannot comment on more complicated matters as I do not consider
what is a fundamentally webprogramming language something I would
use for other purposes.
Axel
------------------------------
Date: Fri, 02 Sep 2005 19:51:13 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <hr3hh1hs1msmhrhoh5h0djouaoc578ik7f@4ax.com>
X-Ftn-To: axel@white-eagle.invalid.uk
axel@white-eagle.invalid.uk wrote:
>> *sniggers* Only if you have little understanding of Perl and little
>> understanding of PHP is required.
>
>It really depends on what you want to do with it. If it just a
>question of picking up some data from a database and displaying it
>on a website, then it is very straight forward.
It is, but you can soon find struggling with php if you want to do something
more => http://tnx.nl/php
--
Matija
------------------------------
Date: 2 Sep 2005 15:10:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Disappearing Module
Message-Id: <df9q15$l8s$1@mamenchi.zrz.TU-Berlin.DE>
Hal Vaughan <hal@thresholddigital.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Hal Vaughan <hal@thresholddigital.com> wrote in comp.lang.perl.misc:
> >> I've had a similar problem before and now I realize it was resolved by
> >> removing a level of modules. I don't see how I can include sample code
> >> unless I include entire modules, but basically, when I do a "use
> >> Module;",
> >> in some cases the functions in that Module aren't available. Here's an
> >> example that works:
> >>
> >> #!/usr/bin/perl
> >> #Program: t-test
> >>
> >> use MyMods::Log;
> >>
> >> ....
> >>
> >> initlog($channel); #This initializes the Log functions
> >>
> >> Then, in MyMods/Log.pm, I have:
> >>
> >> use MyMods::Channel;
> >>
> >> sub initlog {
> >> my $channel = shift(@_);
> >> setchannelprogram($channel); #Routine in MyMods::Channel --
> >> # used w/out problem
> >> return;
> >> }
> >>
> >> When I do this, it works just fine.
> >
> > I doubt that. MyMods/Log.pm doesn't return a true value, Perl
> > will not accept it.
>
> Sorry. I was so focused on the "use" statements and the beginning I forgot
> to include that all modules end with "1;" as the last line, so it does work
> fine without error messages.
>
> >> However, when I add another level, by
> >> having a program use a module that uses MyMods::Log, then MyMod::Log
> >> cannot
> >> access routines in MyMods::Channel. Here's an example of what does not
> >> work:
> >
> > Oh man! Would you please be so kind and explain *what* doesn't work?
> > What error message do you get?
>
> Undefined subroutine &MyMods::Log::setchannelprogram called at MyMods/Log.pm
> line 150.
Okay. That tells me that in your original code there were packages other
than "main" involved. Your code didn't show that.
[more code snipped]
> > I have reconstructed your setup. After adding the missing return values
> > and providing MyMod/Channel.pm
[...]
> > things work exactly as expected: Top level calls initsearch(), which
> > calls initlog(), which calls setchannelprogram(). Since your presented
> > code is incomplete, I have probably fixed something you didn't show.
[...]
> > Now please show the exact and complete code that is giving you trouble,
> > and include the error message you're getting.
>
> Each module is about 500 lines. I am not clear on just how much to include.
Exactly as much as is necessary to reproduce your problem. Apparently
you need three modules and one main program.
[...]
> I have missed because I just never read a particular topic. I've been
> hoping that, in this case, there might have been some rule about module use
> that was so obvious and clear that while I missed it, most people would see
> what I'm not doing.
Nothing of this sort. What you describe should work, and does work when
coded up consistently.
Make a copy of your program and all involved libraries. Throw out every-
thing (in a step-wise process) that doesn't contribute to one of the
functions involved. Replace with dummies what can't be thrown out.
During the process, get the source in runnable condition often and
check if the error is still there. If it goes away, check your last
change. If it is still there, go on paring down the problem.
You will either find your error that way (which is rather likely), or
you'll end up with a minimal program that inexplicably shows the error.
In that case, post it, using copy-and-paste to get the code into the
posting. Then we can talk.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Fri, 02 Sep 2005 09:06:00 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: Re: Unexpected array behaviour
Message-Id: <11hgqimo61a48f3@corp.supernews.com>
Tad McClellan wrote:
> Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote:
>
>
>>Could I have some pointers on how to handle this data better
>
>
>
> You could if we weren't so sarcastic and unhelpful.
>
>
Long memory! LOL.
Caleb
------------------------------
Date: Fri, 2 Sep 2005 11:24:03 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Unexpected array behaviour
Message-Id: <slrndhgv53.1s1.tadmc@magna.augustmail.com>
Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote:
> Tad McClellan wrote:
>> Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com> wrote:
>>
>>
>>>Could I have some pointers on how to handle this data better
>>
>>
>>
>> You could if we weren't so sarcastic and unhelpful.
>>
>>
> Long memory!
Not really, just an extensive scorefile.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 02 Sep 2005 19:39:07 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: values of hash of hash
Message-Id: <mc3hh15pcc6fpqh9tn9f80lec3s9neu62e@4ax.com>
X-Ftn-To: ngoc
ngoc <ngoc@yahoo.com> wrote:
>Each project have many employees, each employee have many tasks, each
>task have time, budget etc... So I did
>
>$data_1{$proj_id}{$employee}{$task} = [$id, $employee, $task,
>$start_time, $budget,.........];
How about,
push @{ $data_1{$proj_id} }, [$id, $employee, $task, ..]
as you already have $employee and $task stored on the right side, and you
don't actually need them in the hash?
>foreach (keys %unique_hash) {
> foreach (keys %{$unique_hash{$_}}) {
> foreach (keys %{$unique_hash{$_}{$_}}) {
> $values = $unique_hash{$_}{$_}{$_};
> }
> }
>}
I guess this isn't your actual code as $_ can't be three different things at
the time?
>Reading from many computer science books, a good programming style is
>not many nested for loop.
Your data structure is fine, but if you're really unhappy with it, build
simple hash with $data_1{$k1, $k2, $k3} = $some_value and later,
#untested
my @data1_keys = keys %data_1;
# assuming $proj_id has only \w chars
my @slice_keys = grep /^$proj_id\b/, @data1_keys;
@unique_hash{@slice_keys} = @data_1{@slice_keys};
#...
for my $k (keys %unique_hash) {
my $values = $unique_hash{$k};
}
Suddenly, even five nested loops look better then this. :)
>Looking back to my app. I use 3 for loop, in many places in my app. So I
>have to change it, IF I WANT TO KEEP my job :-).
Sounds like subroutine could replace your repeating code.
--
Matija
------------------------------
Date: 02 Sep 2005 15:55:03 GMT
From: xhoster@gmail.com
Subject: Re: What is the better method for using hash??
Message-Id: <20050902115503.597$OG@newsreader.com>
"sonet" <sonet.all@msa.hinet.net> wrote:
> How to compare the memory usage??
I'd do it by measuring their memory usages (on a large enough sample), and
then comparing them. I find this to be convenient if not very portable:
print +(`ps -p $$ -o rss `)[1];
> What is the better??
>
> (A)
> hash1{TYPE1}{VALUE1}='A';
> hash1{TYPE1}{VALUE2}='B';
> hash1{TYPE1}{VALUE3}='C';
> hash1{TYPE2}{VALUE1}='1';
>
> or
> (B)
> TYPE1{VALUE1}='A';
> TYPE1{VALUE2}='B';
> TYPE1{VALUE2}='C';
> TYPE2{VALUE1}='1';
Neither is better. A is a syntax error, and B has nothing to do with
hashes (and is also a syntax error if you use strict).
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 8384
***************************************