[23189] in Perl-Users-Digest
Perl-Users Digest, Issue: 5410 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 22 18:07:14 2003
Date: Fri, 22 Aug 2003 15:05:11 -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, 22 Aug 2003 Volume: 10 Number: 5410
Today's topics:
Array access problems (Go Perl)
Re: Array access problems <jkeen@concentric.net>
Re: EZDB <jwillmore@cyberia.com>
Re: EZDB (Ryan)
How can I pack a hash in a well-defined key order (Steve D)
Re: How can I pack a hash in a well-defined key order <kevin@vaildc.net>
Re: How can I put my email address on my website withou <achim.baur@gmx.de>
Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to <dave.nospam@ntlworld.com>
Re: mod_perl - CGI params are undef on large queries <rgarciasuarez@free.fr>
Re: operator in a variable? (Francesc Guasch)
Re: operator in a variable? <michaelr@encraft.com>
Re: operator in a variable? <uri@stemsystems.com>
Re: operator in a variable? <michael.p.broida@boeing.com>
Re: operator in a variable? <uri@stemsystems.com>
Re: operator in a variable? (Tad McClellan)
Re: operator in a variable? <emschwar@pobox.com>
perl LWP UserAgent resume perfomance (Jesse Schoch)
Re: perl LWP UserAgent resume perfomance <bharnish@technologist.com>
Pure Perl SQL server <newsfeed@boog.co.uk>
Quickie UDP Socket Question <mooseshoes@gmx.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Aug 2003 14:27:06 -0700
From: puissant00@yahoo.com (Go Perl)
Subject: Array access problems
Message-Id: <d3825316.0308221327.52d09466@posting.google.com>
The below is my code and i would like to access the last element of
the array
maer_array.
The MAER_FILE looks like the following
ITR Max_error Avg_error Min_error
1 0.849197022974602 0.845806355744732 0.843444019245762
2 0.844939386865682 0.841991065818245 0.837942476416068
3 0.844144961481595 0.841099932356234 0.836919185707587
4 0.844144961481595 0.841099932356234 0.836919185707587
while($maer_line=<MAER_FILE>) {
chop($maer_line);
@maer_array=split(/\t/, $maer_line);
if($maer_array[0] != "ITR") {
#print "$maer_array[3]\n";
}
}
I am having problems accessing the last element and how can i compare
the last element of the 4th column with every element of 4th column
of this file which looks like
ITR CHR SUM Error Error(%)
0 1 46.7058362636031 0.849197022974602 84.9197022974602
0 2 47.0231420611022 0.854966219292767 85.4966219292767
0 3 46.4794258296669 0.845080469630308 84.5080469630308
0 4 46.6549049902152 0.848270999822095 84.8270999822095
0 5 46.8269040494763 0.851398255445024 85.1398255445024
0 6 46.9823066656241 0.854223757556801 85.4223757556801
0 7 46.3894210585169 0.843444019245762 84.3444019245762
0 8 46.4279728814877 0.844144961481595 84.4144961481595
0 9 46.4266047910362 0.844120087109749 84.4120087109749
I am making a mistake somewhere in the storing of arrays and i am not
able to acces the elements of arrays in the manner i want. If anyone
can shed some light on this that would be very helpful.
Regards,
GP
------------------------------
Date: 22 Aug 2003 21:58:36 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Array access problems
Message-Id: <bi63mc$1ia@dispatch.concentric.net>
"Go Perl" <puissant00@yahoo.com> wrote in message
news:d3825316.0308221327.52d09466@posting.google.com...
> The below is my code and i would like to access the last element of
> the array
> maer_array.
> The MAER_FILE looks like the following
> ITR Max_error Avg_error Min_error
> 1 0.849197022974602 0.845806355744732 0.843444019245762
> 2 0.844939386865682 0.841991065818245 0.837942476416068
> 3 0.844144961481595 0.841099932356234 0.836919185707587
> 4 0.844144961481595 0.841099932356234 0.836919185707587
> while($maer_line=<MAER_FILE>) {
> chop($maer_line);
> @maer_array=split(/\t/, $maer_line);
> if($maer_array[0] != "ITR") {
> #print "$maer_array[3]\n";
> }
> }
>
1. Consult documentation (perldoc -f chomp perldoc -f chop) on why you
should use 'chomp' rather than 'chop'.
2. 'ne' is string non-equality operator; '!=' is numeric non-equality
operator.
3. Last element of an array carries index -1.
while (<DATA>) {
chomp;
my @maer_array = split(/\t/);
print "$maer_array[-1]\n" unless ($maer_array[0] eq "ITR");
}
__DATA__
ITR Max_error Avg_error Min_error
1 0.849197022974602 0.845806355744732 0.843444019245762
2 0.844939386865682 0.841991065818245 0.837942476416068
3 0.844144961481595 0.841099932356234 0.836919185707587
4 0.844144961481595 0.841099932356234 0.836919185707587
> I am having problems accessing the last element and how can i compare
> the last element of the 4th column with every element of 4th column
> of this file which looks like
Not quite sure what you mean by "last element of 4th" versus "every element
of 4th". But in any case you can use the -1 index to access the last
element.
------------------------------
Date: Fri, 22 Aug 2003 17:40:37 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: EZDB
Message-Id: <20030822134015.7e9bb93d.jwillmore@cyberia.com>
On 22 Aug 2003 07:47:40 -0700
rlbowley@email.com (Ryan) wrote:
> I don't want to go into the script and modify it to drop the last
> part of the URL if I can avoid it. Has anyone had any problem of
> this sort? Am I cutting my own throat by using EZDB? It does seem
> like support for ezdb has gone out the window. Any help would be
> appreciated.
IMHO, you may want to use the flury of other databases or database
type formats available.
But, again, that's my opinion.
For small databases, with one key, you could use a DBM solution.
For large databases, you could use one of the many open source RDBMS's
avaliable (ie MySQL, PostgreSQL, etc.)
You can even us a CVS flat file solution, but performance is not very
good.
All of these have the appropriate modules to aid in design. (ie there
is the DBD::Pg module, used in conjuction with the DBI module, to
access a PostgreSQL database -or- the DBD::CSV module, used with the
DBI module, to access a CSV flat file datasource).
Again, these are just suggestions.
Jim
------------------------------
Date: 22 Aug 2003 14:01:40 -0700
From: rlbowley@email.com (Ryan)
Subject: Re: EZDB
Message-Id: <77d65ebf.0308221301.3d2630de@posting.google.com>
James Willmore <jwillmore@cyberia.com> wrote in message
> IMHO, you may want to use the flury of other databases or database
> type formats available.
> But, again, that's my opinion.
>
> For small databases, with one key, you could use a DBM solution.
> For large databases, you could use one of the many open source RDBMS's
> avaliable (ie MySQL, PostgreSQL, etc.)
> You can even us a CVS flat file solution, but performance is not very
> good.
>
> All of these have the appropriate modules to aid in design. (ie there
> is the DBD::Pg module, used in conjuction with the DBI module, to
> access a PostgreSQL database -or- the DBD::CSV module, used with the
> DBI module, to access a CSV flat file datasource).
>
> Again, these are just suggestions.
>
> Jim
Thanks for the input. The database is a CSV file anyhow, and I am
going to eventually write my own CGI script and retire the ezdb
program. I am fairly new to perl, but my shell background has sped up
the learning process. I have not had any experience writing CGI, so I
decided to tackle other problems, and use some freeware to help speed
things up. EZDB is not bad, and this is the first real problem I've
had with it. It's really geared towards more complicated things,
including relationals. Anyway, I just thought it was wierd that the
problem only arises w/ netscape six. Not even my old netscape 4 does
this. But that is the only commonality that I see between the
different times this problem has come up (which is ony two, so it is
still very possible that netscape is not the culprit). Thanks again
for the input, now I know where to start when I begin rewriting the
search program.
Ryan
------------------------------
Date: 22 Aug 2003 12:28:41 -0700
From: google.deller@smsail.com (Steve D)
Subject: How can I pack a hash in a well-defined key order
Message-Id: <e41b2b3b.0308221128.3abf06ec@posting.google.com>
I'd like to create (a lot) of message definitions to be used with Pack
and Unpack. There would be a default, with every key defined "in the
correct order" and replacements would be permitted on the fly.
Something like:
my $messages = {
1 => {
Name => "setip",
Data => {
item => 20,
IP_Addr => "100.100.100.100",
Port => 2000,
} ,
Format => "xNxsxN",
} ,
2 => {
...
and then do something like
### pack data for message $m
my %record = %$messages{$m}{Data} ;
### read in a list of field, value pairs
### assume one line with $field ="IP_Addr" and $value =
"200.200.200.200".
$record{$field} = $value ;
### now pack the code
my $data = pack( $$messages{$m}{Format}, @{[%record]} );
### then transmit the data, nicely packed up
This doesn't work because hash key order is undefined.
The Cookbook 5.6 says to use Tie::IxHash, but I can't get that to work
with a reference to an anonymous hash inside a complex structure (even
if I build the structure with a reference to an empty hash and then
call tie on dereference of that reference and then add elements -- in
fact, in that case I can't seem to even add elements to the
dereferenced hash).
So ... how can I set this up, short of retyping all the elements into
an array that is kept with the hash, e.g.
1 => {
Name => "setip",
Data => {
item => 20,
IP_Addr => "100.100.100.100",
Port => 2000,
} ,
Data_Order => [ 'item', 'IP_Addr', 'Port' ] ; # yuk
Format => "xNxsxN",
Regards,
Steve
------------------------------
Date: Fri, 22 Aug 2003 15:39:37 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: How can I pack a hash in a well-defined key order
Message-Id: <kevin-3B9823.15393722082003@news101.his.com>
In article <e41b2b3b.0308221128.3abf06ec@posting.google.com>,
google.deller@smsail.com (Steve D) wrote:
> I'd like to create (a lot) of message definitions to be used with Pack
> and Unpack. There would be a default, with every key defined "in the
> correct order" and replacements would be permitted on the fly.
> Something like:
>
> my $messages = {
> 1 => {
> Name => "setip",
> Data => {
> item => 20,
> IP_Addr => "100.100.100.100",
> Port => 2000,
> } ,
> Format => "xNxsxN",
> } ,
> 2 => {
> ...
>
> and then do something like
> ### pack data for message $m
> my %record = %$messages{$m}{Data} ;
> ### read in a list of field, value pairs
> ### assume one line with $field ="IP_Addr" and $value =
> "200.200.200.200".
> $record{$field} = $value ;
> ### now pack the code
> my $data = pack( $$messages{$m}{Format}, @{[%record]} );
> ### then transmit the data, nicely packed up
>
> This doesn't work because hash key order is undefined.
>
> The Cookbook 5.6 says to use Tie::IxHash, but I can't get that to work
> with a reference to an anonymous hash inside a complex structure (even
> if I build the structure with a reference to an empty hash and then
> call tie on dereference of that reference and then add elements -- in
> fact, in that case I can't seem to even add elements to the
> dereferenced hash).
Tie::IxHash *is* the way to go. It would probably be helpful if you
posted what you tried, because it does work if done properly.
To tie a hash that is stored as a reference inside another hash, for
example $messages->{Data} from above:
tie %{$messages->{Data}}, 'Tie::IxHash';
You have to do this before you put any elements into the hash you're
tying, though.
There may be a better way to handle this, which I'll let others discover
and post.
--
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/
------------------------------
Date: Fri, 22 Aug 2003 17:26:31 +0200
From: Achim Baur <achim.baur@gmx.de>
Subject: Re: How can I put my email address on my website without attracting Spam?
Message-Id: <bi5cng$5fuq4$1@ID-13112.news.uni-berlin.de>
Mr. Clean wrote:
> Several ways. I used E_Cloaker to munge the links
> http://www.codefoot.com/software/ecloaker/index.shtml
I tried that and think it's an easy to use method which suits my needs
allright. Thanx mr. clean.
------------------------------
Date: Fri, 22 Aug 2003 21:53:43 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: IN SEARCH OF ELEGANT CODE: Setting a hash value to a chomp'ed thing
Message-Id: <qnirfnivyyragyjbeyqpbz.hk1ulja.pminews@text.news.ntlworld.com>
On 22 Aug 2003 07:41:59 GMT, Tassilo v. Parseval wrote:
>grep() runs through the list (in this case `which ps` that happens to
>only have one element) and applies the code given as first argument
>(chomp). If this code snippet returns a true value for a particular list
>element, this item is allowed to pass through. It's a filter
>essentially.
Oh - I was not aware that grep could take anything other than a regex -
too used to "real" grep I guess :-)
Thank you - I think :-)
Regards
Dave Saville
NB switch saville for nospam in address
------------------------------
Date: 22 Aug 2003 19:46:46 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: mod_perl - CGI params are undef on large queries
Message-Id: <slrnbkct5u.hnv.rgarciasuarez@dat.local>
Martin Glaude wrote in comp.lang.perl.misc :
> I have a relatively simple form-handling perl script running under
> Apache/2.0.40 (Vanilla RedHat 9 install).
>
> The script runs perfectly fine in all cases when mod_perl is not used.
>
> The script runs fine under mod_perl so long as the totally data sent
> along with the post request doesn't exceed ~1k.
Do you use a GET or a POST method ? Forms submitted via GET encode their
values in the URL and are thus length-limited.
> A large data field exists (or several smaller ones, I suppose), calls to
> $query->param('whatever') return no data, no matter what field is
> checked. Note: This happens on the very first query to a freshly
> reloaded server, so I don't think it's a variable scope problem that can
> happen in mod_perl.
To know this, enable warnings and check the error_log. See also the
various great docs at http://perl.apache.org/ .
> I am quite perplexed. Is there a switch or parameter that needs to be
> set to increase the memory allocation? Is there a bug in my build of
> Apache?
There are no built-in limitations in perl, if you want to know :)
I'd recommend to build your own apache and your own mod_perl. (And your
own perl, maybe -- although RedHat 9 comes with a perl that is more
recent than the latest official stable release, 5.8.0.) But that's a
personal preference -- I like to tune things.
--
Unmanageable is not *NIX
------------------------------
Date: 22 Aug 2003 10:04:28 -0700
From: frankieremovethis@etsetb.upc.es (Francesc Guasch)
Subject: Re: operator in a variable?
Message-Id: <12932a23.0308220904.58a20e91@posting.google.com>
"Janek Schleicher" <bigj@kamelfreund.de> wrote in message news:<pan.2003.08.22.09.30.45.759549@kamelfreund.de>...
> Michael Roper wrote at Fri, 22 Aug 2003 01:54:20 -0700:
>
> > Is it possible to store pieces of an expression in a variable that will get
> > expanded before the larger expression is evaluated? For example, could I
> perldoc -f eval
> my $result = eval "$x $op $y";
> eval STRING is one of the things that you usually won't use unless you
> really want to use it :-)
eval is not evil, only use it with caution.
If something wrong happens running the code, the variable $@ will have
the error string.
my $result = eval "$x $op $y";
if ($@) {
# something was wrong ...
warn $@; # will show the error
# you can do something about it.
}
------------------------------
Date: Fri, 22 Aug 2003 10:54:15 -0700
From: "Michael Roper" <michaelr@encraft.com>
Subject: Re: operator in a variable?
Message-Id: <bi5lc9$5bakf$1@ID-160215.news.uni-berlin.de>
Janek Schleicher writes:
> May I ask what the problem is you need to evaluate operators for.
Sure, maybe that's for the best. :) I have tried eval and can't get
anything to work. I need to modify a script that represents my one and only
foray into Perl, it was done a year ago, and I'm sure there's a better way.
(Also, any corrections to tortured terminology, concepts or usage on my part
is appreciated. Whatever I learned a year ago is now fuzzy at best.)
I'm starting with an ugly log generated by my server-side spam blocker. I
use one script to nicely format that log and strip out any entry that is not
a description of a blocked email. The result is a complete list of all
blocked emails, with each record formatted as (in a fixed-width font):
-----------------------------------------------------------------
Date: 04.06.2003 07:42:43
IP: 12.255.39.76
Sender: de59jgn1@mail.com
Recipient: michaelr@encraft.com
Response: 550 5.2.1 Mailbox unavailable.
Reason: SPAMCOP [Spam Source, Various Others -- 127.0.0.2]
Details: Blocked - see http://spamcop.net/bl.shtml?12.255.39.76
Blacklist: www.spamcop.net
Lookup: www.spamcop.net/w3m?action=checkblock&ip=12.255.39.76
-----------------------------------------------------------------
Because of the volume of blocked emails that need to be checked (for
collateral damage), I wrote a second script that further strips out log
records that are, for whatever reason, guaranteed to be spam and don't need
to be manually confirmed.
It's the second script I'm having trouble with. One of the main goals in
writing it was to make it easy to manually add, modify, or delete (within
the script itself) the "definitely spam" descriptions used to cull records
from the log. For that, I use:
my @aDelete =
({
Name => 'open relay',
Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
Count => "0",
},{
Name => 'china and korea',
Marker=> ' (china|korea) does not seem to care about spam$',
Count => "0",
});
When I process the log, I check each log entry ($sLogRecord) against each
Marker. If it's found, I increment the Count for the Marker. When I'm
done, I use the Name and Count for each Marker to display a summary table of
the results, as well as any log records that survived deletion (and
therefore need to be checked as possible collateral damage):
foreach $sLogRecord ( @aLogRecords )
{
#---------------------------------------------------------------------------
-----------------#
# compare against marker of each record type to be deleted
#---------------------------------------------------------------------------
-----------------#
for( $i = 0; $i <= $#aDelete; $i++ )
{
if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
{
$aDelete[$i]->{Count}++;
$sLogRecord = undef;
}
}
}
This may be ugly, but it has worked well and I've been able to easily modify
the entries in @aDelete as needed. The problem I have now is that for the
first time I'd like to delete a record if it doesn't match a particular
Marker. So, I'd like to add an entry to @aDelete such as:
{
Name => 'invalid recipient',
Marker=> '^Recipient: michaelr@encraft\.com)$',
Count => "0",
}
and then rather than:
if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
do this instead:
if( $sLogRecord !~ /$aDelete[$i]->{Marker}/m )
It seemed to me that the cleanest way to do this was to include the desired
operator in the @aDelete entry itself:
my @aDelete =
({
Name => 'invalid recipient',
Marker=> '^Recipient: michaelr@encraft\.com)$',
Op => "!~",
Count => "0",
},{
Name => 'open relay',
Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
Op => "=~",
Count => "0",
},{
Name => 'china and korea',
Marker=> ' (china|korea) does not seem to care about spam$',
Op => "=~",
Count => "0",
});
But I have been unable to find a way to then write:
if( $sLogRecord $aDelete[$i]->{Op} /$aDelete[$i]->{Marker}/m )
that will work in the intended fashion. I have tried every permutation of
eval I can think of.
I realize that I can solve this problem in other ways. It's just that the
only solutions I've come up with are pretty ugly. Any thoughts much
appreciated.
Michael Roper
------------------------------
Date: Fri, 22 Aug 2003 18:26:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: operator in a variable?
Message-Id: <x7fzjtpmzp.fsf@mail.sysarch.com>
>>>>> "FG" == Francesc Guasch <frankieremovethis@etsetb.upc.es> writes:
>> perldoc -f eval
>> my $result = eval "$x $op $y";
>> eval STRING is one of the things that you usually won't use unless you
>> really want to use it :-)
FG> eval is not evil, only use it with caution.
no, only use eval when is does something that is much harder (or
impossible) to do in other ways. caution is too light a word especially
when newbies are asking about eval. almost all eval uses by newbies can
be done with better and safer with hashes, code refs, dispatch tables,
etc.
the point is that eval is a last resort and not the first technique to
try. it is very rarely needed and used way too often. so the 'dogma'
here is to never support its use unless you have a clear understanding
of what it does, how it can be unsafe and a very strong reason why it is
the best solution.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 22 Aug 2003 20:12:14 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: operator in a variable?
Message-Id: <3F46791E.B1745814@boeing.com>
Michael Roper wrote:
>
> Janek Schleicher writes:
> > May I ask what the problem is you need to evaluate operators for.
>
> Sure, maybe that's for the best. :) I have tried eval and can't get
> anything to work. I need to modify a script that represents my one and only
> foray into Perl, it was done a year ago, and I'm sure there's a better way.
> (Also, any corrections to tortured terminology, concepts or usage on my part
> is appreciated. Whatever I learned a year ago is now fuzzy at best.)
>
> I'm starting with an ugly log generated by my server-side spam blocker. I
> use one script to nicely format that log and strip out any entry that is not
> a description of a blocked email. The result is a complete list of all
> blocked emails, with each record formatted as (in a fixed-width font):
>
> -----------------------------------------------------------------
> Date: 04.06.2003 07:42:43
>
> IP: 12.255.39.76
> Sender: de59jgn1@mail.com
> Recipient: michaelr@encraft.com
>
> Response: 550 5.2.1 Mailbox unavailable.
> Reason: SPAMCOP [Spam Source, Various Others -- 127.0.0.2]
> Details: Blocked - see http://spamcop.net/bl.shtml?12.255.39.76
>
> Blacklist: www.spamcop.net
> Lookup: www.spamcop.net/w3m?action=checkblock&ip=12.255.39.76
> -----------------------------------------------------------------
>
> Because of the volume of blocked emails that need to be checked (for
> collateral damage), I wrote a second script that further strips out log
> records that are, for whatever reason, guaranteed to be spam and don't need
> to be manually confirmed.
>
> It's the second script I'm having trouble with. One of the main goals in
> writing it was to make it easy to manually add, modify, or delete (within
> the script itself) the "definitely spam" descriptions used to cull records
> from the log. For that, I use:
>
> my @aDelete =
> ({
> Name => 'open relay',
> Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
> Count => "0",
> },{
> Name => 'china and korea',
> Marker=> ' (china|korea) does not seem to care about spam$',
> Count => "0",
> });
>
> When I process the log, I check each log entry ($sLogRecord) against each
> Marker. If it's found, I increment the Count for the Marker. When I'm
> done, I use the Name and Count for each Marker to display a summary table of
> the results, as well as any log records that survived deletion (and
> therefore need to be checked as possible collateral damage):
>
> foreach $sLogRecord ( @aLogRecords )
> {
>
> #---------------------------------------------------------------------------
> -----------------#
> # compare against marker of each record type to be deleted
>
> #---------------------------------------------------------------------------
> -----------------#
> for( $i = 0; $i <= $#aDelete; $i++ )
> {
> if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
> {
> $aDelete[$i]->{Count}++;
> $sLogRecord = undef;
> }
> }
> }
>
> This may be ugly, but it has worked well and I've been able to easily modify
> the entries in @aDelete as needed. The problem I have now is that for the
> first time I'd like to delete a record if it doesn't match a particular
> Marker. So, I'd like to add an entry to @aDelete such as:
>
> {
> Name => 'invalid recipient',
> Marker=> '^Recipient: michaelr@encraft\.com)$',
> Count => "0",
> }
>
> and then rather than:
>
> if( $sLogRecord =~ /$aDelete[$i]->{Marker}/m )
>
> do this instead:
>
> if( $sLogRecord !~ /$aDelete[$i]->{Marker}/m )
>
> It seemed to me that the cleanest way to do this was to include the desired
> operator in the @aDelete entry itself:
>
> my @aDelete =
> ({
> Name => 'invalid recipient',
> Marker=> '^Recipient: michaelr@encraft\.com)$',
> Op => "!~",
> Count => "0",
> },{
> Name => 'open relay',
> Marker=> '^ Reason: (NJABL|OSIRUSOFT) \[Open Relay',
> Op => "=~",
> Count => "0",
> },{
> Name => 'china and korea',
> Marker=> ' (china|korea) does not seem to care about spam$',
> Op => "=~",
> Count => "0",
> });
>
> But I have been unable to find a way to then write:
>
> if( $sLogRecord $aDelete[$i]->{Op} /$aDelete[$i]->{Marker}/m )
>
> that will work in the intended fashion. I have tried every permutation of
> eval I can think of.
Combine that with someone's prior suggestion involving
using functions for the operators. Put the FUNCTION NAME
in your "Op" entry and call that function to perform the
operation needed.
Mike
------------------------------
Date: Fri, 22 Aug 2003 21:17:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: operator in a variable?
Message-Id: <x74r09pf3m.fsf@mail.sysarch.com>
>>>>> "MPB" == Michael P Broida <michael.p.broida@boeing.com> writes:
please edit the quoted post.
<snip of full quote>
MPB> Combine that with someone's prior suggestion involving
MPB> using functions for the operators. Put the FUNCTION NAME
MPB> in your "Op" entry and call that function to perform the
MPB> operation needed.
and that is getting back to symrefs which are bad.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 22 Aug 2003 13:46:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: operator in a variable?
Message-Id: <slrnbkcp78.1vt.tadmc@magna.augustmail.com>
Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "FG" == Francesc Guasch <frankieremovethis@etsetb.upc.es> writes:
>
> >> my $result = eval "$x $op $y";
> FG> eval is not evil, only use it with caution.
>
> no, only use eval when is does something that is much harder (or
> impossible) to do in other ways. caution is too light a word especially
> when newbies are asking about eval. almost all eval uses by newbies can
> be done with better and safer with hashes, code refs, dispatch tables,
> etc.
For those of you following along at home, you should note that
what is being discussed here is the "eval EXPR" form.
"eval BLOCK" is not evil.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 22 Aug 2003 15:55:42 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: operator in a variable?
Message-Id: <etooeyh4ash.fsf@wormtongue.emschwar>
Uri Guttman <uri@stemsystems.com> writes:
>>>>>> "MPB" == Michael P Broida <michael.p.broida@boeing.com> writes:
> MPB> Combine that with someone's prior suggestion involving
> MPB> using functions for the operators. Put the FUNCTION NAME
> MPB> in your "Op" entry and call that function to perform the
> MPB> operation needed.
>
> and that is getting back to symrefs which are bad.
A way of doing the same thing that doesn't require symrefs is to use
a hash of subrefs:
my %funcHs = ( '+' => sub { $_[0] + $_[1] },
'-' => sub { $_[0] - $_[1] },
'*' => sub { $_[0] * $_[1] },
'/' => sub { $_[0] / $_[1] } );
Then call it like so:
my $op = '+';
print $funcHs{$op}->(1, 2), "\n";
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 22 Aug 2003 13:39:44 -0700
From: greenail@yahoo.com (Jesse Schoch)
Subject: perl LWP UserAgent resume perfomance
Message-Id: <9de9fcb4.0308221239.6f4fc2ce@posting.google.com>
I'm seeing very high CPU utilization during my sub that is handeling a
HTTP resume with LWP. Is there a good way to buffer $chunk so I'm not
not doing IO ops for each byte? I can't just slurp it into memory
because the file is huge, but i could read available mem and make a
calculation for a safe buffer to use, problem is that i'm not much of
a perl IO guru. Any ideas?
Here is the sub
open (SAVE,">>$save");
$response = $ua->request($req,
sub
{
my($chunk, $res) = @_;
binmode SAVE;
print SAVE $chunk;
$transferred += length($chunk);
printf STDERR "\rTransferred: %d Kb", ($transferred / 1000);
}
);
close(SAVE);
Forgive my syntax, it's the only way i can read my own code.
-greenail
------------------------------
Date: Fri, 22 Aug 2003 21:04:02 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: perl LWP UserAgent resume perfomance
Message-Id: <pan.2003.08.22.21.04.26.802805@technologist.com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On Fri, 22 Aug 2003 13:39:44 -0700, Jesse Schoch wrote:
> I'm seeing very high CPU utilization during my sub that is handeling a
> HTTP resume with LWP. Is there a good way to buffer $chunk so I'm not
> not doing IO ops for each byte? I can't just slurp it into memory
> because the file is huge, but i could read available mem and make a
> calculation for a safe buffer to use, problem is that i'm not much of
> a perl IO guru. Any ideas?
>
> Here is the sub
> open (SAVE,">>$save");
> $response = $ua->request($req,
> sub
> {
> my($chunk, $res) = @_;
> binmode SAVE;
> print SAVE $chunk;
> $transferred += length($chunk);
> printf STDERR "\rTransferred: %d Kb", ($transferred / 1000);
> }
> );
> close(SAVE);
>
> Forgive my syntax, it's the only way i can read my own code.
>
> -greenail
yeah, look into 'perldoc LWP::Useragent', it says there is a third param
to request(), put the block (chunk) size in. You could preform your code
about like this:
$respone = $ua->request(
$req,
sub {
print SAVE, $_[0];
printf STDERR "\rTransfered: %d KB", ++$transfered;
},
1024
);
BTW: 1Kb = 1 KiloBit. 1KB = 1 KiloByte. Also, 1KB = 1024 Bytes, not 1000.
(2**10 not 10**3).
- Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/RoUgiK/rA3tCpFYRAi4pAKDGD2AA1f7dtJrwp0EB1wkSk54m2ACgyZmv
n8PHSKLuNLNRIYbmxhIYwPQ=
=fSE7
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 22 Aug 2003 21:59:52 +0100
From: "Peter Cooper" <newsfeed@boog.co.uk>
Subject: Pure Perl SQL server
Message-Id: <bi609d$5n8hp$1@ID-194358.news.uni-berlin.de>
Does anyone know of a pure Perl SQL server? I have noticed the rise of 'pure
Perl' modules for things like XML parsing, and the pure Perl DBD::MySQLPP,
but have never seen anything as ambition as a pure Perl SQL server.
I am not entirely sure as to how useful such a thing would be, although it'd
make a cute part time project, as there's bound to be tons of things I'd
learn along the way. With Perl6/Parrot approaching rapidly, I believe such
pure Perl systems could come into their own, as Perl's speed rockets up the
y-axis.
This is just blustering at this point, but I'd be interested to hear what
other people think. My searches for such a project have been fruitless,
except for a post on a LUG mailing list where someone was asking for a pure
Perl SQL server, but that was four years ago, and he got no replies! :-)
I have looked at SQL::Statement which does a little parsing for DBD::CSV,
although I have yet to take a good look into DBD::CSV itself. I believe
there's potential to developing a 'reasonably' powerful SQL engine in pure
Perl, and if it's developed with Perl 6 in mind, it may become a rather
useful tool in the future.
Thoughts? Hisses? Sarky comments? Insights? :-)
Regards,
Peter Cooper
------------------------------
Date: 22 Aug 2003 21:09:54 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Quickie UDP Socket Question
Message-Id: <bi60r2$a2l@dispatch.concentric.net>
All:
I need to know if the 'while' statement below will be true if the client
sends a message with an empty packet (eg. $client_message is empty). In
other words, is it sufficient for the client to contact the port or must
the client have something to say?
<code snip>
use Socket;
<code snip>
socket(SockHandle, PF_INET, SOCK_DGRAM, getprotobyname("udp"))
|| die "socket: $!";
<code snip>
while ($client_portaddr = recv(SockHandle, $client_message, $MAXLEN, 0)) {
# do something
}
Thanks!
Moose
------------------------------
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 5410
***************************************