[23411] in Perl-Users-Digest
Perl-Users Digest, Issue: 5629 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 7 14:07:07 2003
Date: Tue, 7 Oct 2003 11:05:08 -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, 7 Oct 2003 Volume: 10 Number: 5629
Today's topics:
cgi,htaccess,mysql <ryan@dctnet.net>
Re: fastest count of instances in string? (Roy Johnson)
Re: GD::Graph: "mixed" graph doesn't recognize "area" g (Emilio Mayorga)
GDBM_File problems <mhunter@uclink.berkeley.edu>
NEWBIE! Please help! (BDK)
Re: NEWBIE! Please help! <peter@semantico.com>
Re: NEWBIE! Please help! <tom@ztml.com>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <perl@my-header.org>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <kevin@vaildc.net>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() (Randal L. Schwartz)
Re: Opinions on "new SomeObject" vs. "SomeObject->new() (Randal L. Schwartz)
Re: Opinions on "new SomeObject" vs. "SomeObject->new() <kevin@vaildc.net>
Re: Opinions on "new SomeObject" vs. "SomeObject->new() (Greg Bacon)
Re: Opinions on "new SomeObject" vs. "SomeObject->new() (Lack Mr G M)
Re: parse boolean logic <sv99oya02@sneakemail.com>
Perl Command line for stat (nos)
Re: Perl::Inline compiling problems <kalinaubears@iinet.net.au>
Re: Perl::Inline compiling problems <kalinaubears@iinet.net.au>
Re: Reading huge *.txt files? <hobbes@vkr.NOSPAM.dk>
Re: Reading huge *.txt files? <REMOVEsdnCAPS@comcast.net>
Would you please make clear your word little more ? <mo@naggama.co.kr>
Re: Would you please make clear your word little more <HelgiBriem_1@hotmail.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Oct 2003 13:56:52 -0400
From: "Ryan Howe" <ryan@dctnet.net>
Subject: cgi,htaccess,mysql
Message-Id: <pan.2003.10.07.17.56.51.191364@dctnet.net>
Hello, (*Note Some of this may be considered off topic)
I was hoping someone could point me in the right direction on this.
Basically what I have is a cgi script that I want protected by htaccess.
Not a problem, but I want it to authenticate against a MySQL database. I
looked into mod_mysql_auth but it is not suitable for many reasons
(trouble compiling,breaks other things etc.). Anyway is there a way that I
use a directive in httpd.conf (using apache by the way) to have htaccess
use a perl script to authenticate and then return that back to the
htaccess for acceptance or denial? Sorry if this is either unclear or if
I should be asking this somewhere else (if so tell me and I will not
bother you folks).
Thank you,
Ryan
------------------------------
Date: 7 Oct 2003 08:59:17 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: fastest count of instances in string?
Message-Id: <3ee08638.0310070759.e2fd774@posting.google.com>
Better benchmark code produces more satisfying benchmarks. Note the
addition of a method using "index", which is not too shabby.
I noticed that adding \Q to the patterns (so that I matched strings
rather than re's) slowed them down, so I cached the pattern matches.
They had been running about 4x as slow as cached tr///, but reduced
the difference to less than a factor of 2.
Results:
scc : uses s///g: 8.5 sec
mcc : uses m//g with scalar map to count results: 10.8 sec
mcc2: uses m//g with an explicit loop and counter: 11.9 sec
trcc: cached subs of eval tr///: 6.4 sec
tacc: same, but using arrays instead of hashes to cache: 6.0 sec
incc: uses index and explicit counter: 7.9 sec
Notes:
The spec is to count occurrences of single characters. Most of these
methods generalize:
tacc will only do individual characters
trcc will do character classes
the others will do substrings (though the patterns could be
rewritten to match classes instead)
Using index is surprisingly fast, and requires no caching
scc returns empty string instead of zero
Code:
#!perl
use strict;
use warnings;
my $str = 'abccdeageabbcab';
my @chars = qw(a b c d e f g);
my $count;
my $sub = \&mcc;
my %cache = ();
my @cache = ();
for (1..100000) {
$count = &$sub($_, $str) for (@chars);
}
for (@chars) {
$count = &$sub($_, $str);
print "There are $count ${_}s in $str\n";
}
sub mcc {
my ($c, $s) = @_;
$cache{$c} ||= qr/\Q$c/;
scalar map(/$cache{$c}/g, $s);
}
sub mcc2 {
my ($c, $s) = @_;
my $count = 0;
$cache{$c} ||= qr/\Q$c/;
++$count while $s=~/$cache{$c}/g;
$count;
}
sub trcc {
my ($c, $s) = @_;
$cache{$c} ||= eval "sub { \$_[0] =~ tr/$c// }";
$cache{$c}->($s);
}
sub tacc {
my ($c, $s) = @_;
$cache[ord $c] ||= eval "sub { \$_[0] =~ tr/$c// }";
$cache[ord $c]->($s);
}
sub scc {
my ($c, $s) = @_;
$cache{$c} ||= qr/\Q$c/;
scalar $s=~s/$cache{$c}//g;
}
sub incc {
my ($c, $s) = @_;
my $count = 0;
my $pos = index($s, $c);
while ($pos >= 0) {
++$count;
$pos = index($s, $c, $pos+1);
}
$count;
}
------------------------------
Date: 7 Oct 2003 10:50:51 -0700
From: e.mayorga@co.snohomish.wa.us (Emilio Mayorga)
Subject: Re: GD::Graph: "mixed" graph doesn't recognize "area" graph type
Message-Id: <faa70e85.0310070950.484e244@posting.google.com>
e.mayorga@co.snohomish.wa.us (Emilio Mayorga) wrote in message news:<faa70e85.0310061616.437e484a@posting.google.com>...
> > I've had a bit of a look at it, but I can't really see what's wrong with
> > it (if anything at all). Would it be possible for you to just fill the
> > $sensorgraph{$sensorid} hashes with some decent values, and then run the
> > GD::Graph part separately? if you then still see problems, please email
> > the result to me, because that probably means there is some bug or
> > oddity that I need to have a look at.
>
> Thanks for looking into it. I'll try to do that test, but a deadline
> is creeping up on me, so it may be a while. I'll definitely try to
> follow up if the problem persists. I expect to make heavy use of
> GD::Graph for several projects in the future.
I've found the problem. The error message comes up when there are
undef values in the area graph. I was able to reproduce it in
sample61.pl by just setting one of the area graph values to undef.
I suppose there is logic to why an area graph would not work when
there is an undef, but the error message is misleading.
I rearranged how my graphs are created so that the area graphs would
have no undef's. That eliminated the error messages, but it also
eliminated the graphs intended to be area graphs! They don't show up.
I haven't figured out what's going on.
On a more general note, it seems restrictive to have to associate all
graphs with exactly the same set of x-values, especially for a numeric
x-axis (continuous values). *BUT*, I really appreciate the work you've
done in putting together this module.
Thanks.
-Emilio
------------------------------
Date: Tue, 7 Oct 2003 17:43:52 +0000 (UTC)
From: Mike Hunter <mhunter@uclink.berkeley.edu>
Subject: GDBM_File problems
Message-Id: <slrnbo5uqr.o9.mhunter@celeste.net.berkeley.edu>
Can somebody point me to the perl tgz file for this? I am getting:
"Can't locate loadable object for module GDBM_File in @INC (@INC contains..."
Thanks,
Mike
------------------------------
Date: 7 Oct 2003 09:08:59 -0700
From: bdknoll@runbox.com (BDK)
Subject: NEWBIE! Please help!
Message-Id: <dffcb909.0310070808.82e2f3a@posting.google.com>
I am trying to take a peice of a word and replace it with output of
the chr function. So the word is ki45. I want to replace the 45 with
what "print (chr(36));" returns.
Here is what I have tried:
$word = ki45;
$word =~ s/(45)/(print (chr(chr36))/;
print ($word);
print "\n";
but that returns:
ki(print (chr(chr36))
I have also tried:
$test = print (chr(chr36);
$word = ki45;
$word =~ s/(45)/$test/;
print ($word);
print "\n";
but that returns this:
ki1
I'm assuming the 1 is "true", but I want the output which should be $.
Any help would be greatly appreciated. Thanks.
------------------------------
Date: Tue, 07 Oct 2003 17:32:48 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: NEWBIE! Please help!
Message-Id: <3f82eab3$0$17366$afc38c87@news.easynet.co.uk>
BDK wrote:
> I am trying to take a peice of a word and replace it with output of
> the chr function. So the word is ki45. I want to replace the 45 with
> what "print (chr(36));" returns.
>
> Here is what I have tried:
>
> $word = ki45;
> $word =~ s/(45)/(print (chr(chr36))/;
Remember print just writes its arguments to stdout, it doesnt return anything
usefull. So the print on the line above is bogus. You are in effect replacing
45 with the return value of print (and print DOES NOT return its arguments, it
just prints them).
> print ($word);
> print "\n";
>
> but that returns:
> ki(print (chr(chr36))
>
>
> I have also tried:
> $test = print (chr(chr36);
> $word = ki45;
> $word =~ s/(45)/$test/;
> print ($word);
> print "\n";
Almost but you are using print again, try this:
$test = chr(36);
$word = ki45;
$word =~ s/45/$test/;
print $word;
print "\n";
>
> but that returns this:
> ki1
When I said that print returned nothing useful what it does return is true /
1. Which is why the output is 1.
You are overdoing the use of '(' and ')', it will just confuse you, besides
'(' and ')' actually have some meaning in a regex.
>
> I'm assuming the 1 is "true", but I want the output which should be $.
>
> Any help would be greatly appreciated. Thanks.
------------------------------
Date: Tue, 07 Oct 2003 17:22:33 GMT
From: tom <tom@ztml.com>
Subject: Re: NEWBIE! Please help!
Message-Id: <tDCgb.27892$kD3.18798@nwrdny03.gnilink.net>
bdknoll - runbox.com (BDK) wrote:
>I am trying to take a peice of a word and replace it with output of
>the chr function. So the word is ki45. I want to replace the 45 with
>what "print (chr(36));" returns.
>
>Here is what I have tried:
>
>$word = ki45;
>$word =~ s/(45)/(print (chr(chr36))/;
.
Use sprintf for the above:
$word =~ s/(45)/sprintf ("%s",chr(36))/e;
Tom
ztml.com
------------------------------
Date: Tue, 07 Oct 2003 17:23:38 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <2dm5ov4rsksluvjvnkhpvra73o6phobesn@4ax.com>
X-Ftn-To: Randal L. Schwartz
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>Greg> What's worse, at least in the context of Perl, is that you're being
>Greg> rigidly dogmatic. If you don't like $obj->new, then don't use it!
>
>The problem is that your use of ->new is not likely to be confined to
>your cubicle. I don't speak for your private code. I speak for code
>that you're likely to upload to the CPAN to share with others.
>
>Don't make $instance->new. It obscures more than it communicates.
I think you really should explain that in foreword of Damian book. :)
--
Matija
------------------------------
Date: Tue, 07 Oct 2003 12:29:30 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <kevin-157A5F.12292707102003@news101.his.com>
In article <f233f2f0.0310070654.739c0c7b@posting.google.com>,
quantum_mechanic_1964@yahoo.com (Quantum Mechanic) wrote:
> The last one makes me wish for an alias to 'ref' called 'ClassOf'.
> Indeed, getting the 3rd ancestor class might be done like this:
>
> $new_great_great_uncle = (ClassOf($Johny,3))->new();
>
> for certain values of ClassOf.
Except that this doesn't work very well with multiple inheritance.
--
Bright eyes/burning like fire, | Kevin Michael Vail
Bright eyes/how can you close and fail? | kevin@vaildc.net
How can the light that shone so brightly | . . . . . . . . . .
Suddenly shine so pale?/Bright eyes | . . . . . . . . .
------------------------------
Date: Tue, 07 Oct 2003 16:31:57 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Matija Papec <perl@my-header.org>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <1381708c35ef3e5dd03ea2a534b8349d@news.teranews.com>
>>>>> "Matija" == Matija Papec <perl@my-header.org> writes:
>> Don't make $instance->new. It obscures more than it communicates.
Matija> I think you really should explain that in foreword of Damian book. :)
I make the point in the Alpaca. Is that enough?
--
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: Tue, 07 Oct 2003 16:45:56 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <2e9662bee965bc458112632e5d557ef3@news.teranews.com>
>>>>> "Kevin" == Kevin Michael Vail <kevin@vaildc.net> writes:
Kevin> Except that this doesn't work very well with multiple inheritance.
Some would claim that "multiple inheritance" is itself to blame.
:-)
--
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: Tue, 07 Oct 2003 13:18:05 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <kevin-FE43A1.13180507102003@news101.his.com>
In article <2e9662bee965bc458112632e5d557ef3@news.teranews.com>,
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Kevin" == Kevin Michael Vail <kevin@vaildc.net> writes:
>
> Kevin> Except that this doesn't work very well with multiple inheritance.
>
> Some would claim that "multiple inheritance" is itself to blame.
Well, yeah, but it's useful sometimes. I only use it for "mixin" things.
--
Bright eyes/burning like fire, | Kevin Michael Vail
Bright eyes/how can you close and fail? | kevin@vaildc.net
How can the light that shone so brightly | . . . . . . . . . .
Suddenly shine so pale?/Bright eyes | . . . . . . . . .
------------------------------
Date: Tue, 07 Oct 2003 17:38:45 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <vo5uh58f3jgr68@corp.supernews.com>
In article <51a53c247078236ccbf45909c38c6207@news.teranews.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
: >>>>> "Greg" == Greg Bacon <gbacon@hiwaay.net> writes:
:
: Greg> Here you argue in horribly obtuse terms: "If you want an
: Greg> instance method called 'new', I have no idea what it's doing."
: Greg> Bull! In the next two sentences, you give *two* ideas. If you
: Greg> not sure, read the pods, or use the source, Luke!
:
: I should have said "I have no idea which of the following two it is
: doing, or something else entirely." Does that help?
No, because your argument is still obtuse. This is Perl: you have the
message's surrounding context, you have the pods, and you have the
source. You must be at least this tall to ride.
: Greg> What's worse, at least in the context of Perl, is that you're
: Greg> being rigidly dogmatic. If you don't like $obj->new, then don't
: Greg> use it!
:
: The problem is that your use of ->new is not likely to be confined to
: your cubicle. I don't speak for your private code. I speak for code
: that you're likely to upload to the CPAN to share with others.
Now you're being paternalistic and tilting at windmills. Yes, we
could all put together contrived examples that are problematic in
this respect, but only if the subject programmer can't be bothered
to look at the pods or source.
Greg
--
Democracy becomes a government of bullies tempered by editors.
-- Ralph Waldo Emerson
------------------------------
Date: Tue, 07 Oct 2003 18:41:33 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
Message-Id: <2003Oct7.184133@ukwit01>
In various articles someone or other wrote:
|>
|> For creating new objects, I think that
|>
|> $new_object = new Object;
|>
|> makes intuitive sense -- "give me a new Object".
Except that it is actually:
$new_object = new Class;
and you are *not* asking for a new class.
|> $new_object = Object->new();
|>
|> makes less sense to me
Similarly, this is really:
$new_object = Class->new();
and you are asking the Class to implement a new(). So for me this
latter one makes more sense, in English.
|> Don't make $instance->new. It obscures more than it communicates.
That's what documentation is for. Using something without first
reading the instructions is Not a Good Idea.
I have a class which has 2 constructors and *neither* of then is
called new. It's a security token module which can either be created by
internally calling an issuing server (with id+pwd) or from a
previously-obtained token.
So, my code looks like:
my $tko1 = MyToken->from_token('token' => $token);
my $tko2 = MyToken->via_login('id' => yourid, 'password' => yourpassword);
Some poeple seem to be advocating this conveying more:
my $tko1 = from_token MyToken('token' => $token);
my $tko2 = via_login MyToken('id' => yourid, 'password' => yourpassword);
I can't see it myself.
--
--------- Gordon Lack --------------- gml4410@ggr.co.uk ------------
This message *may* reflect my personal opinion. It is *not* intended
to reflect those of my employer, or anyone else.
------------------------------
Date: Tue, 07 Oct 2003 18:23:16 +0200
From: =?ISO-8859-1?Q?Steffen_M=FCller?= <sv99oya02@sneakemail.com>
Subject: Re: parse boolean logic
Message-Id: <blup92$o8i$1@news.rz.uni-karlsruhe.de>
Thomas Reat wrote:
> I have a perl script that must take some boolean logic as input.
> Something like:
>
> ((a || b) & !c) || d || (e && f)
>
> Is there any module out there that can help me parse this? And
> evaluate it as well?
>
> Ideally I would pass it the expression and a hash (or callback) to get
> the values of each variable. And it returns the value of the whole
> expression. But if there's nothing that does that, I'm interested in
> anything that helps with this.
As Sam pointed out earlier, Parse::RecDescent can easily parse such
expressions. You can find a working example grammar for more involved
*arithmetic* expressions in the Math::Symbolic::Parser module that is
part of the Math::Symbolic distribution. It should be fairly easy to
modify it to work for boolean logic.
http://search.cpan.org/src/SMUELLER/Math-Symbolic-0.124/lib/Math/Symbolic/Parser.pm
Steffen
--
@n=([283488072,6076],[2105905181,8583184],[1823729722,9282996],[281232,
1312416],[1823790605,791604],[2104676663,884944]);$b=6;@c=' -/\_|'=~/./g
;for(@n){for$n(@$_){map{$h=int$n/$b**$_;$n-=$b**$_*$h;$c[@c]=$h}reverse
0..11;push@p,map{$c[$_]}@c[reverse$b..$#c];$#c=$b-1}$p[@p]="\n"}print@p;
------------------------------
Date: 7 Oct 2003 10:52:23 -0700
From: nos41@hotmail.com (nos)
Subject: Perl Command line for stat
Message-Id: <e06c9226.0310070952.7e20bed8@posting.google.com>
I am trying to use a command line Perl –e to stat a file with in
Solaris. I was looking for someone that can modify the line so it
will work from a command line. I have not been able to figure out the
right format to use. Can someone please help me with this.
Perl –e ‘(stat($filename)) [10]' any suggestions
------------------------------
Date: Wed, 08 Oct 2003 03:15:43 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Perl::Inline compiling problems
Message-Id: <3f82f578$0$23615$5a62ac22@freenews.iinet.net.au>
Brian K. Michalk wrote:
> Sisyphus <kalinaubears@iinet.net.au> wrote in message news:<3f821856$0$23589$5a62ac22@freenews.iinet.net.au>...
>
>>Sisyphus wrote:
>>
>>
>>>Caveat:
>>>1) The source file ('s1.c') needs to be in a separate directory from
>>>'try.pl'. (Or maybe it just needs to be in a directory other than the
>>>cwd - haven't tested.)
>>>
>>
>>'perldoc inline-faq' tells us that the C source files must be in a
>>subdirectory of the perl script.
>>
>>Cheers,
>>Rob
>
>
> Where did you get that?
> http://search.cpan.org/~ingy/Inline-0.44/Inline-FAQ.pod mentions
> nothing about this. Perhaps I'm using way outdated documentation?
It's in there - in the section 'How do I create a binary distribution
using inline'.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Wed, 08 Oct 2003 03:23:42 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Perl::Inline compiling problems
Message-Id: <3f82f757$0$23608$5a62ac22@freenews.iinet.net.au>
Brian K. Michalk wrote:
> Thank you so much. Who would have thought about the subdirectory
> thing. I guess it's symlinks for me.
>
> Strange about the AV* thing. I'm doing it for execution efficiency
> ... why else would I use C? Perl -v says I'm using 5.6.1. Is there
> some documentation on this "feature"?
>
I've always had to use the Stack to pass arrays to Inline C. (See
'perldoc Inline::C-Cookbook' on how to pass varying size argument
lists.) Afaik it wasn't until 5.8 that you could pass AV*s, courtesy of
a fixed typemap. But if you're experiencing no problem .... maybe you've
got a 5.6 with a fixed typemap.
(I'll check my facts, too - and report back if I've got it wrong.)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Tue, 7 Oct 2003 17:10:05 +0200
From: "Jesper" <hobbes@vkr.NOSPAM.dk>
Subject: Re: Reading huge *.txt files?
Message-Id: <blukva$ibk$1@news.net.uni-c.dk>
> However this is still not the way, even if TIMTOWTDI.
>
> Before you read txta read txtb into a hash
>
> foreach $txtb_line (@txtb}
> {
> my (@array) = $txtb_line =~ m!(.*);(.*)!;
> $lookup{$array[0]} = $array[1];
> }
>
> then where you had the inner loop
>
> if($lookup{$userid}) {
> $userinfo = $lookup{$userid};
> } else {
> $userinfo = '';
> }
>
> Don't go much faster.
>
Thx, that works pretty darn nice - it takes about 6 secs. to do 240.000.000
comparisons :)
Regards
Jesper
------------------------------
Date: Tue, 07 Oct 2003 12:03:02 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Reading huge *.txt files?
Message-Id: <Xns940D84B85680Asdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Jesper" <hobbes@vkr.NOSPAM.dk> wrote in
news:bluigq$gap$1@news.net.uni-c.dk:
> I have the same problem.
> I have two txt files (txta and texb) each with 15-20000 lines. Each
> line contains a username + info. Now what I want to do is take a line
> from texta, retrieve the username from this line, search for the
> username in txtb and return the info that's related to the username i
> txtb. My code looks like:
>
> open (txta, "txta");
> @txta= <txta>;
> close(txta);
>
> open (txtb, "txtb");
> @txtb= <txtb>;
> close(txtb);
>
> foreach $txta_line (@txta)
> {
[Eric gets out the Holy Baseball Bat of Education]
Do NOT [whap!] read [whap!] an entire *file* [whap!] into an *array*
[whap!] just so you can [whap!] loop [whap!] over it!!! [whap-whap-whap!]
[Eric puts the baseball bat away]
Okay, now that we're in the proper frame of mind for some education:
One: You read an entire file (txta) into an array, then apparently do
nothing more than loop over that array. This is Bad. [don't make me get
the baseball bat out again.] It's a waste of memory, and it doesn't buy
you anything. It's foolish. It means that you copied a bad habit from
some bad book or bad instructor.
Two: You read another entire file (txtb) into memory, and repeatedly loop
over it in search of user ids. In this case, it's not entirely hopeless
that you slurped the entire file into memory, because you're referencing
it frequently, but there's a better way. Read through the txtb file,
finding userids, and put them into a hash, and reference them while going
through txta. That way you will only have to scan file txtb once.
Something like this:
my %uid_lookup;
while (<txtb>)
{
chomp; # (?)
$uid_lookup{$1} = $2 if /(.*);(.*)/;
}
while (<txta>)
{
get userid;
$userinfo = $uid_lookup{$userid};
...
}
There. One pass per file. No huge arrays in memory (although, who knows
how large %uid_lookup can get?).
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP4LxsWPeouIeTNHoEQIGtQCfXsffnYbsXe1F5ph2Z21mUBU/HwQAnA8W
05GqIlnA5zusx6yRqyX7PyP4
=Wk1v
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 8 Oct 2003 02:03:48 +0900
From: "Mo" <mo@naggama.co.kr>
Subject: Would you please make clear your word little more ?
Message-Id: <blurbo$2q8$1@news.hananet.net>
Thanks for your answer Anno.
Would you please make clear your word little more ?
"Use a HTML parser from CPAN"
I don't really get it, since I'm just beginner on programming.
Regards
Mo
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:blu3hh$kau$1@mamenchi.zrz.TU-Berlin.DE...
> G&G <chang@naggama.co.kr> wrote in comp.lang.perl.misc:
> > Have any idea about regular expression ?
> >
> >
> > I tried to change any numeric letter to Zero like following;
> > $aaa = ereg_replace ("|0-9|", "0", $sentence);
> > This seems working perfect.
> >
> > My question is how I can do this function only for outside of html tags.
> > I don't want any numeric letters to be changed inside html tags.
>
> HTML cannot reasonably be parsed by a regex alone. Use a HTML parser
> from CPAN.
>
> Anno
------------------------------
Date: Tue, 07 Oct 2003 17:14:02 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Would you please make clear your word little more ?
Message-Id: <mis5ovk2hgi2s8p0og0hc8417achklkmlq@4ax.com>
On Wed, 8 Oct 2003 02:03:48 +0900, "Mo" <mo@naggama.co.kr> wrote:
First, don't start a new thread to followup an existing
article unless the subject changes radically.
Second, don't top-post. It annoys the regulars and
seriously damages your chances of receiving
useful answers to your questions. If you don't know
what top-posting is, read:
http://www.catb.org/~esr/jargon/html/T/top-post.html
For further guidelines on posting to comp.lang.perl.misc read:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
For more information about netiquette in general, see the
"Netiquette Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
>"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
>news:blu3hh$kau$1@mamenchi.zrz.TU-Berlin.DE...
>> G&G <chang@naggama.co.kr> wrote in comp.lang.perl.misc:
>> > Have any idea about regular expression ?
>> >
>> >
>> > I tried to change any numeric letter to Zero like following;
>> > $aaa = ereg_replace ("|0-9|", "0", $sentence);
>> > This seems working perfect.
>> >
>> > My question is how I can do this function only for outside of html tags.
>> > I don't want any numeric letters to be changed inside html tags.
>>
>> HTML cannot reasonably be parsed by a regex alone. Use a HTML parser
>> from CPAN.
>Would you please make clear your word little more ?
>
>"Use a HTML parser from CPAN"
>
>I don't really get it, since I'm just beginner on programming.
He means to go to the Comprehensive Perl Archive Network,
where all publicly available Perl modules are stored:
http://search.cpan.org/
There you can find, download and install a HTML parser module.
The standard one is HTML::Parser which is part of the core
in recent Perl distributions, but it is a little hard to use for
a beginner.
HTML::TokeParser::Simple is much easier to use and
there are even simpler ones.
Contrary to popular opinion, parsing HTML *is* close to
rocket science and is not a job for a beginner's hand coding.
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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.
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 5629
***************************************