[29157] in Perl-Users-Digest
Perl-Users Digest, Issue: 401 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 3 14:09:49 2007
Date: Thu, 3 May 2007 11:09:06 -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 Thu, 3 May 2007 Volume: 11 Number: 401
Today's topics:
Access hash of hashes element problem. <justin.0704@purestblue.com>
Re: Access hash of hashes element problem. <paduille.4061.mumia.w+nospam@earthlink.net>
Re: convert a bitmap file into a jpg file ? <lev.weissman@creo.com>
Re: Dynamic DNS management <noozegoy@pookmail.com>
Re: Dynamic DNS management <nobull67@gmail.com>
Re: FAQ 4.51 How do I permute N elements of a list? <brian.d.foy@gmail.com>
File::Grep g4173c@motorola.com
Re: File::Grep <paduille.4061.mumia.w+nospam@earthlink.net>
Re: File::Grep <xicheng@gmail.com>
Re: Help on expanding variable from sh jdoe987@gmail.com
Re: Help on expanding variable from sh <mritty@gmail.com>
Re: Help on expanding variable from sh jdoe987@gmail.com
Re: Help on expanding variable from sh <mritty@gmail.com>
Re: Help on expanding variable from sh <bik.mido@tiscalinet.it>
Re: Help on expanding variable from sh <xicheng@gmail.com>
Re: Help with Pattern matching. Matching multiple lines <xicheng@gmail.com>
Re: ignorance and intolerance in computing communties <xah@xahlee.org>
Re: ignorance and intolerance in computing communties <ignoramus12143@NOSPAM.12143.invalid>
Re: ignorance and intolerance in computing communties <fb@frank-buss.de>
Re: ignorance and intolerance in computing communties <rschroev_nospam_ml@fastmail.fm>
Re: Sockets xhoster@gmail.com
Web Forms / Perl / SPAM detection <uctraing@ultranet.com>
Re: Web Forms / Perl / SPAM detection jayjuliano@gmail.com
Re: Web Forms / Perl / SPAM detection <spamtrap@dot-app.org>
Re: Web Forms / Perl / SPAM detection <no@email.com>
Re: Web Forms / Perl / SPAM detection <nobull67@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 May 2007 15:39:59 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Access hash of hashes element problem.
Message-Id: <slrnf3enqf.9es.justin.0704@stigmata.purestblue.com>
I can't seem to access the values in a hash of hashes, but if I iterate
over it I'm able to print all the values. The error I get if I try to
access one value is :
Use of uninitialized value in print at ./test line 20, <PRICES> line 62.
I've done the best I can in reducing this to the smallest possible code
that works, it's still quite long, sorry about that.
======= START CODE =======
#!/usr/bin/perl
use warnings ;
use strict ;
my %priceHash ;
my $zone = 5 ;
my $weight = 5 ;
lookupCost() ;
#for $weight ( keys %priceHash ) {
# print "$weight : " ;
# for $zone ( keys %{$priceHash{$weight}} ) {
# print "\t", $zone, "=", $priceHash{$weight}{$zone}, "\n" ;
# }
# print "\n" ;
#}
print "Price = ", $priceHash{$weight}{$zone}, "\n" ;
sub lookupCost {
open PRICES, "<", "/var/www/inhouse/pforce/pforcePrices.csv"
or die "Cannot opne prices csv file: $!" ;
my @lines = <PRICES> ;
my $header = shift @lines ;
chomp $header ;
$header =~ s/\cM//g ; # MS CR/LF
$header =~ s/zone//ig ;
$header =~ s/\s+//g ;
my @zones = split /,/ , $header ;
shift @zones ; #first one is empty
foreach ( @lines ) {
chomp ;
s/\cM//g ;
my @prices = split /,/ ;
my $kg = shift @prices ;
foreach ( @zones ) {
$priceHash{$kg}{$_} = shift @prices ;
}
}
}
======= CODE END =======
If I comment the "print" line and uncomment the itteration over the
hashes it prints, for each weight, the different zones and the prices
for those zones. It appears to me that all of the information is in the
hash but I'm not accessing the individual values correctly.
The .csv, if you want to try this out, can be found at:
http://81.6.247.208/pforcePrices.csv I didn't paste it here because of
the size (it's not too big, but it's not appropriate for a usenet post).
I thank you for any help you can give with this.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 01 May 2007 17:29:06 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Access hash of hashes element problem.
Message-Id: <CNKZh.7221$j63.3948@newsread2.news.pas.earthlink.net>
On 05/01/2007 10:39 AM, Justin C wrote:
> I can't seem to access the values in a hash of hashes, but if I iterate
> over it I'm able to print all the values. The error I get if I try to
> access one value is :
> Use of uninitialized value in print at ./test line 20, <PRICES> line 62.
> [...]
Your program is so close to working, but you have one problem--you
forgot that hash keys are strings and only strings. Where string
comparisons are concerned, '5' != '5.0'. Change $weight (at the top of
the program) to "5.0" and rerun your program.
However, it's better to create the hash keys as simpler numbers, e.g.
insert 5 rather than 5.0:
$priceHash{$kg+0}{$_} = shift @prices;
This causes a warning about "per" which has some function in your data
that I don't know about.
I also have two minor nickpicks: "open" is misspelled in the die()
statement, and the PRICES file is never explicitly closed by program.
You also do a little more work than is necessary to read in the data.
This is a shorter version of your program:
use strict;
use warnings;
use File::Slurp;
my %priceHash;
my $weight = 5;
my $zone = 5;
my @lines = read_file('pforcePrices.csv');
s/\cM\cJ$// for @lines;
my $header = shift @lines;
$header =~ s/(zone|\s+|^,)//ig;
my @zones = split /,/,$header;
foreach my $line (@lines) {
next unless $line =~ /^\d/;
my @prices = split /,/,$line;
my $kg = shift @prices;
foreach my $zn (@zones) {
$priceHash{$kg+0}{$zn} = shift @prices;
}
}
print "Price: $priceHash{$weight}{$zone}\n";
------------------------------
Date: 3 May 2007 07:02:12 -0700
From: MoshiachNow <lev.weissman@creo.com>
Subject: Re: convert a bitmap file into a jpg file ?
Message-Id: <1178200932.489694.47630@y80g2000hsf.googlegroups.com>
On May 3, 1:56 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On 3 May 2007 02:39:06 -0700, MoshiachNow <lev.weiss...@creo.com>
Thanks
------------------------------
Date: Thu, 03 May 2007 10:51:02 -0600
From: Nooze Goy <noozegoy@pookmail.com>
Subject: Re: Dynamic DNS management
Message-Id: <f1d0cp0ue@news3.newsguy.com>
Brian McCauley wrote:
> On May 2, 12:42 am, Nooze Goy <nooze...@pookmail.com> wrote:
>> I'm in the process of setting up a web server - actually, it's pretty
>> much working, just a few irritating things lurking about, occasionally
>> leaping out and biting me on the arse.
>>
>> One of the irritations is that with a dynamic DNS, I'm having to update
>> the IP addresses for the authoritative DNS server of multiple domains
>> hosted here. They're on one DNS service, ZoneEdit, and I found a couple
>> of pieces of code to update the IP addresses. One was ddclient, but
>> before I could get the config debugged, I tried another - which is not
>> so much a program as a command-line. It works okay, except that
>> ZoneEdit's server is agonizingly slow to respond, so it takes ten or
>> fifteen seconds to respond for each domain.
>>
>> wget -O - --http-user=mylogin --http-passwd=myp455
>> 'http://dynamic.zoneedit.com/auth/dynamic.html?host=my.domain.com'
>>
>> In the script, the above line is repeated for each domain; each line
>> takes ten or fifteen seconds to process - doesn't seem reasonable, butt
>> hu nose?
>>
>> Obviously, with five or six domains, you're going to be hard-pressed to
>> update the IP every minute,
>
> Unless you spawn 5 or 6 wget commands at once.
How?
------------------------------
Date: 3 May 2007 10:27:59 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Dynamic DNS management
Message-Id: <1178213279.728732.97770@q75g2000hsh.googlegroups.com>
On May 3, 5:51 pm, Nooze Goy <nooze...@pookmail.com> wrote:
> Brian McCauley wrote:
> > On May 2, 12:42 am, Nooze Goy <nooze...@pookmail.com> wrote:
[ talking about a Unix shell script ]
> >> wget -O - --http-user=mylogin --http-passwd=myp455 'http://dynamic.zoneedit.com/auth/dynamic.html?host=my.domain.com'
>
> >> In the script, the above line is repeated for each domain; each line
> >> takes ten or fifteen seconds to process
> >> Obviously, with five or six domains, you're going to be hard-pressed to
> >> update the IP every minute,
>
> > Unless you spawn 5 or 6 wget commands at once.
>
> How?
You are asking (in a Perl newsgroup) how, in a Unix shell script, to
indicate that the script should not wait for one command to complete
before going on to the next!
What's wrong with this picture?
Oh, well, I guess seeing as it's a single character answer:
&
------------------------------
Date: Tue, 01 May 2007 09:41:03 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.51 How do I permute N elements of a list?
Message-Id: <010520070941032681%brian.d.foy@gmail.com>
In article <87k5vtwil3.fsf@gemini.sunstarsys.com>, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
> PerlFAQ Server <brian@stonehenge.com> writes:
>
> > #!/usr/bin/perl -n
> > # Fischer-Kause ordered permutation generator
>
> Oops. It's the Fischer-Krause algorithm- spot the missing "r".
Fixed. Thanks :)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 3 May 2007 08:36:17 -0700
From: g4173c@motorola.com
Subject: File::Grep
Message-Id: <1178206577.223928.202670@e65g2000hsc.googlegroups.com>
Hi:
I'm trying to get the match string from fgrep with the following code:
use File::Grep qw (fgrep);
foreach $log (@logfile) {
@match = fgrep { /HOSTNAME/ } "$log";
...
do_lots_more
}
however this is only returning a HASH(xxx). I assume it doesn't like
the
"$log" which is the path to the file. How can I correct this?
Thanks!
Tom
------------------------------
Date: Thu, 03 May 2007 17:12:14 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: File::Grep
Message-Id: <OJo_h.7776$j63.3745@newsread2.news.pas.earthlink.net>
On 05/03/2007 10:36 AM, g4173c@motorola.com wrote:
> Hi:
>
> I'm trying to get the match string from fgrep with the following code:
>
> use File::Grep qw (fgrep);
> foreach $log (@logfile) {
> @match = fgrep { /HOSTNAME/ } "$log";
> ...
> do_lots_more
> }
>
>
> however this is only returning a HASH(xxx). I assume it doesn't like
> the
> "$log" which is the path to the file. How can I correct this?
>
> Thanks!
> Tom
>
No, it looks like a bug in the module. You might e-mail the author. This
is a workaround for right now:
my @matching_lines;
fgrep { push @matching_lines, $_ if /HOSTNAME/ } $log;
And here is another solution:
use File::Slurp qw(read_file);
my @matching_lines = grep /HOSTNAME/, read_file($log);
------------------------------
Date: 3 May 2007 10:40:25 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: File::Grep
Message-Id: <1178214025.667554.202190@n76g2000hsh.googlegroups.com>
On May 3, 11:36 am, g41...@motorola.com wrote:
> Hi:
>
> I'm trying to get the match string from fgrep with the following code:
>
> use File::Grep qw (fgrep);
> foreach $log (@logfile) {
> @match = fgrep { /HOSTNAME/ } "$log";
1) you dont have to add quotation marks with $log.
2) the returned array elements are designed as filehandle-like
objects, not the filenames. If you print out the returned hash
reference, you can easily know how to extract the corresponding
filename..try the following:
foreach my $log (@logfile) {
my @match = fgrep { /HOSTNAME/ } $log;
print $_->{filename} for @match;
# do more stuff
}
Good luck,
Xicheng
------------------------------
Date: 3 May 2007 07:07:17 -0700
From: jdoe987@gmail.com
Subject: Re: Help on expanding variable from sh
Message-Id: <1178201237.419314.40720@h2g2000hsg.googlegroups.com>
Michele,
Thanks for the advice. Unfortunately, I had already tries the env
option and it does not seem to work. I have tried escaping it as
well. Any other ideas? Thanks again.
perl -e 'alarm(3); exec qw/rsh -n $ENV{4HOST} uname/' - error
generates
$ENV{HOST}: unknown host
perl -e 'alarm(3); exec qw/rsh -n $ENV{$HOST} uname/' - error
generates
$ENV{$HOST}: unknown host
perl -e 'alarm(3); exec qw/rsh -n \$env{'HOST'}\ uname/' - for some
reason this is the only one that works. It reports on the first host
(incorrectly I may add) then spews out
\$env{HOST}\: unknown host
On May 2, 3:48 pm, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On 2 May 2007 12:36:56 -0700, jdoe...@gmail.com wrote:
>
> >This may sound like a simple question - but I am a newbie at perl.
>
> You welcome!
>
> >Most of my scripting is in sh. Anyway - I am having problems with the
>
> You will switch gradually, if needed.
>
> >command below. specifically in the perl command.
>
> >for HOST in `ypcat netgroup| grep foobar;; do ping $HOST 2 >> /dev/
> >null; if [ $? -eq 0 ]; then perl -e 'alarm(3); exec qw/rsh -n \{$HOST}
> >\ uname -a /'; fi;done
>
> Perl usage is really minimal here.
>
> >The $HOST variable is only being expanded on the first host. After
>
> So far I think you have a shell quoting problem. To go on topic,
> however, you can access the $HOST environment variable directly IN
> Perl by means of the %ENV variable. $ENV{HOST} should do the trick.
>
> 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: 3 May 2007 07:36:59 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Help on expanding variable from sh
Message-Id: <1178203019.228013.153590@n59g2000hsh.googlegroups.com>
On May 3, 10:07 am, jdoe...@gmail.com wrote:
> Michele,
> Thanks for the advice. Unfortunately, I had already tries the env
> option and it does not seem to work. I have tried escaping it as
> well. Any other ideas? Thanks again.
>
> perl -e 'alarm(3); exec qw/rsh -n $ENV{4HOST} uname/' - error
> generates
> $ENV{HOST}: unknown host
>
> perl -e 'alarm(3); exec qw/rsh -n $ENV{$HOST} uname/' - error
> generates
> $ENV{$HOST}: unknown host
>
> perl -e 'alarm(3); exec qw/rsh -n \$env{'HOST'}\ uname/' - for some
> reason this is the only one that works. It reports on the first host
> (incorrectly I may add) then spews out
> \$env{HOST}\: unknown host
>
Please don't multipost. Please see the answer to this question in the
perl.beginners list/group. Basically, stop using qw// when you mean
qq//. If you really want to avoid the shell (which is the only reason
I know of to pass a list rather than a string), you'll have to build
your list manually:
exec('rsh', '-n', $ENV{HOST}, 'uname');
Paul Lalli
------------------------------
Date: 3 May 2007 07:48:17 -0700
From: jdoe987@gmail.com
Subject: Re: Help on expanding variable from sh
Message-Id: <1178203697.223276.48270@e65g2000hsc.googlegroups.com>
Paul,
I was simply replying back to Michele and asking for any help on
understanding and addressing the issue. The posting simply an ongoing
thread to the original post. That being said - your suggestion of
using qq// seemed to do the trick. Thanks.
On May 3, 10:36 am, Paul Lalli <mri...@gmail.com> wrote:
> On May 3, 10:07 am, jdoe...@gmail.com wrote:
>
>
>
> > Michele,
> > Thanks for the advice. Unfortunately, I had already tries the env
> > option and it does not seem to work. I have tried escaping it as
> > well. Any other ideas? Thanks again.
>
> > perl -e 'alarm(3); exec qw/rsh -n $ENV{4HOST} uname/' - error
> > generates
> > $ENV{HOST}: unknown host
>
> > perl -e 'alarm(3); exec qw/rsh -n $ENV{$HOST} uname/' - error
> > generates
> > $ENV{$HOST}: unknown host
>
> > perl -e 'alarm(3); exec qw/rsh -n \$env{'HOST'}\ uname/' - for some
> > reason this is the only one that works. It reports on the first host
> > (incorrectly I may add) then spews out
> > \$env{HOST}\: unknown host
>
> Please don't multipost. Please see the answer to this question in the
> perl.beginners list/group. Basically, stop using qw// when you mean
> qq//. If you really want to avoid the shell (which is the only reason
> I know of to pass a list rather than a string), you'll have to build
> your list manually:
> exec('rsh', '-n', $ENV{HOST}, 'uname');
>
> Paul Lalli
------------------------------
Date: 3 May 2007 08:29:30 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Help on expanding variable from sh
Message-Id: <1178206170.640729.177960@e65g2000hsc.googlegroups.com>
On May 3, 10:48 am, jdoe...@gmail.com wrote:
> Paul,
> I was simply replying back to Michele and asking for any help on
> understanding and addressing the issue. The posting simply an ongoing
> thread to the original post.
Yes, and because you multi-posted your original question, I wasted
time answering you in perl.beginners without being able to know that
you'd also asked the question here and had started another thread on
it.
Don't multipost. It's rude.
Paul Lalli
------------------------------
Date: Thu, 03 May 2007 18:13:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Help on expanding variable from sh
Message-Id: <mh2k339elo2shasaijssa84dqh05oq2fe0@4ax.com>
On 3 May 2007 07:36:59 -0700, Paul Lalli <mritty@gmail.com> wrote:
>Please don't multipost. Please see the answer to this question in the
>perl.beginners list/group. Basically, stop using qw// when you mean
>qq//. If you really want to avoid the shell (which is the only reason
D'Oh! Hadn't even noticed...
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: 3 May 2007 10:57:20 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Help on expanding variable from sh
Message-Id: <1178215040.005779.99350@y80g2000hsf.googlegroups.com>
On May 2, 3:36 pm, jdoe...@gmail.com wrote:
> This may sound like a simple question - but I am a newbie at perl.
> Most of my scripting is in sh. Anyway - I am having problems with the
> command below. specifically in the perl command.
>
> for HOST in `ypcat netgroup| grep foobar;; do ping $HOST 2 >> /dev/
> null; if [ $? -eq 0 ]; then perl -e 'alarm(3); exec qw/rsh -n \{$HOST}
> \ uname -a /'; fi;done
>
> The $HOST variable is only being expanded on the first host. After
> that it loops stating:
> {$HOST}: unknown host
>
> Any help and an explanation on what the correct syntax is would be
> appreciated.
Hi,
You might also want to try Perl 's -s switch on the command line to
pass shell varaibles into Perl:
perl -se 'alarm(3); exec("rsh -n $host uname -a")' -- -
host="$HOST"
(Note: '--' is needed to tell Perl that all switches finished there),
Regards,
Xicheng
------------------------------
Date: 3 May 2007 11:02:35 -0700
From: Xicheng Jia <xicheng@gmail.com>
Subject: Re: Help with Pattern matching. Matching multiple lines from while reading from a file.
Message-Id: <1178215355.366181.114780@y80g2000hsf.googlegroups.com>
On May 2, 11:37 pm, "Bobby Chamness" <b_chamn...@comcast.net> wrote:
> Example from a file I'm reading.
>
> 2007-04-17 09:35:34 ACSSA[0]:
> 1431 N sa_demux.c 1 276
> drive 4, 1, 1,11: Library error, Transport failure
>
> I want to match the first and third line, that way I know the date and
> drive info.
>
> so the output on the print will look like this
> 2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
> failure
If all independent records are seperated by empty line, and you want
to remove the second line of all the three-line records, then
perl -00pe 's/\n.*\n/ /' file.txt
Regards,
Xicheng
------------------------------
Date: 3 May 2007 07:49:33 -0700
From: Xah Lee <xah@xahlee.org>
Subject: Re: ignorance and intolerance in computing communties
Message-Id: <1178203772.243333.24990@p77g2000hsh.googlegroups.com>
Xah Lee wrote:
=C2=AB
.=2E.
=E2=80=9CIgnorance And Intolerance In Online Computing Communities=E2=80=9D
http://xahlee.org/Netiquette_dir/ignorance_intolerance.html
.=2E. As i have indicated in my post, it is non-trivial to implement a
function that returns the positive angle of a vector....
=C2=BB
I have now coded this. I think it is probably the most algorithmically
optimal, and rather much simpler than i originally thought. Here's the
Mathematica code:
vectorAngle[{a1_, a2_}] :=3D Module[{x, y},
{x, y} =3D {a1, a2}/Sqrt[a1^2 + a2^2] // N;
If[x =3D=3D 0 && y =3D=3D 0, "fucked",
If[x =3D=3D 0, If[Sign@y =3D=3D=3D 1, =CF=80/2, -=CF=80/2],
If[y =3D=3D 0, If[Sign@x =3D=3D=3D 1, 0, =CF=80],
If[Sign@y =3D=3D=3D 1, ArcCos@x, 2 =CF=80 - ArcCos@x]
]
]
]
]
Btw, if we can use any Mathematica's buildin function, this is
actually just
vectorAngle2[{a1_, a2_}] :=3D Arg@(Complex @@ {a1, a2})
I'm still interested, if someone would show the source code, of how
Perl, Python, or Lisp or Java, implement the function that finds the
angle of a complex number.
Originally, i was also hoping perhaps there's some math trick by dot
product or combination of trig functions, that obviates the need to
check which quadrant the vector is in ...
Xah
xah@xahlee.org
=E2=88=91 http://xahlee.org/
------------------------------
Date: Thu, 03 May 2007 10:01:21 -0500
From: Ignoramus12143 <ignoramus12143@NOSPAM.12143.invalid>
Subject: Re: ignorance and intolerance in computing communties
Message-Id: <po6dnV9VaIXcZKTbnZ2dnUVZ_vGinZ2d@giganews.com>
It is not that difficult to those of us who know math. Obvious analogy
to the function below exists in 'perl'.
double vectorAngle( double x, double y )
{
double r2 = x*x+y*y;
if( r2 == 0 ) return -10; // error case
int quadrant = x > 0 ? (y >= 0 : 0 : 3) : (y > 0 ? 1 : 2);
return pi/2 * quadrant + asin( abs(y)/sqrt( r2 ) );
}
------------------------------
Date: Thu, 3 May 2007 17:11:13 +0200
From: Frank Buss <fb@frank-buss.de>
Subject: Re: ignorance and intolerance in computing communties
Message-Id: <tm2zrm0fpi3p.6ioc9058rocf$.dlg@40tude.net>
Xah Lee wrote:
> I'm still interested, if someone would show the source code, of how
> Perl, Python, or Lisp or Java, implement the function that finds the
> angle of a complex number.
So you have forgotten to cross-post to comp.lang.java :-)
I think at least for strict floating-point Java uses the netlib:
http://www.netlib.org/fdlibm/e_atan2.c
For normal floating-point calculations I assume Java uses something like
FPATAN on x86'er computers:
http://www.ews.uiuc.edu/~cjiang/reference/vc107.htm
But you can download the source code of the JVM to verify it yourself:
https://openjdk.dev.java.net/
--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
------------------------------
Date: Thu, 03 May 2007 16:04:22 GMT
From: Roel Schroeven <rschroev_nospam_ml@fastmail.fm>
Subject: Re: ignorance and intolerance in computing communties
Message-Id: <aKn_h.155468$VX2.1150061@phobos.telenet-ops.be>
Xah Lee schreef:
> Xah Lee wrote:
> «
> ...
> “Ignorance And Intolerance In Online Computing Communities”
> http://xahlee.org/Netiquette_dir/ignorance_intolerance.html
>
> ... As i have indicated in my post, it is non-trivial to implement a
> function that returns the positive angle of a vector....
> »
>
> I have now coded this. I think it is probably the most algorithmically
> optimal, and rather much simpler than i originally thought. Here's the
> Mathematica code:
>
> vectorAngle[{a1_, a2_}] := Module[{x, y},
> {x, y} = {a1, a2}/Sqrt[a1^2 + a2^2] // N;
> If[x == 0 && y == 0, "fucked",
> If[x == 0, If[Sign@y === 1, π/2, -π/2],
> If[y == 0, If[Sign@x === 1, 0, π],
> If[Sign@y === 1, ArcCos@x, 2 π - ArcCos@x]
> ]
> ]
> ]
> ]
I might be wrong of course, but can't you just use atan2? Only problem
is that it returns negative angles for quadrants 3 and 4, but that is
easily solved. In Python:
from math import atan2, pi, fmod
def vectorAngle(x, y):
return fmod(atan2(y, x) + 2*pi, 2*pi)
No conditionals in sight.
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
------------------------------
Date: 01 May 2007 16:07:58 GMT
From: xhoster@gmail.com
Subject: Re: Sockets
Message-Id: <20070501120800.257$Gu@newsreader.com>
Monty <dale.schmitz@offutt.af.mil> wrote:
> Ok, having read the IO::Select perldoc, I can make some sense out of
> what it's telling me, and the sample code seems clearer than what I've
> found on the web (you're right Martien: how could I NOT expect
> comments on any code posted :) ). A couple of things still elude me,
> though. If I understand correctly, the sample code in the perldoc
> creates a new socket object with $lsn = IO::Socket::INET(etc...) and
> then a new IO::Select object is created with $sel = IO::Select($lsn).
Yes. The first creates a socket that listens for incoming connections.
The second lets you listen for those incoming connections without blocking.
> With that latter statement, my understanding is that an array-like
> object named $sel is created,
I have no idea what *you* consider to be "array-like". $sel is an
IO::Select object. If IO::Select objects are "array-like" to you, then it
is array-like. But I suspect you will find it less confusing to just accept
that IO::Select is what it is, rather than trying to force it into
classifications like "array-like"
> and $sel can/will contain file handles
> to communications streams going through the socket object, $lsn.
$sel "contains" file handles. Initially, $lsn is the only file handle it
contains. As the code operates, new file handles (sockets created by
accepting connections negotiated through $lsn) are added to $sel. These
new connections, once established, are no longer related to $lsn.
So "$sel->can_read" is basically saying "Wait either for a new connection
to be ready to be accepted, or until one of the already accepted
connections has sent me data"
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 03 May 2007 13:40:44 GMT
From: - Bob - <uctraing@ultranet.com>
Subject: Web Forms / Perl / SPAM detection
Message-Id: <ihpj33le6br0jo7lfqmd6quq7anrnem7pl@4ax.com>
I have some web forms that are getting hit by spammers sending spam
into the system. They are simple forms, add your name, address, etc.
Perl code handles the form, of course!
I'd like to cut down on the spammers. I was thinking that perhaps I
could check the person's IP against blacklists... but most of the
blacklists I know of are mail servers, so I am not sure that is
practical. I am hoping to avoid the "enter this displayed secret code"
mechanism as an annoyance for legit users. But, I am open to
suggestions on existing Perl based solutions (trails blazed before
me!) or just pointers to good resources on programmable solutions to
this issue.
Thanks,
------------------------------
Date: 3 May 2007 09:10:48 -0700
From: jayjuliano@gmail.com
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <1178208648.759712.298970@e65g2000hsc.googlegroups.com>
On May 3, 8:40 am, - Bob - <uctra...@ultranet.com> wrote:
> I have some web forms that are getting hit by spammers sending spam
> into the system. They are simple forms, add your name, address, etc.
> Perl code handles the form, of course!
>
> I'd like to cut down on the spammers. I was thinking that perhaps I
> could check the person's IP against blacklists... but most of the
> blacklists I know of are mail servers, so I am not sure that is
> practical. I am hoping to avoid the "enter this displayed secret code"
> mechanism as an annoyance for legit users. But, I am open to
> suggestions on existing Perl based solutions (trails blazed before
> me!) or just pointers to good resources on programmable solutions to
> this issue.
>
> Thanks,
Utilize a 'Captcha' system. Have your Perl script generate an image
with a 5 character text code. Then force the user to type the text in
the image before submitting. This will stop bots.
------------------------------
Date: Thu, 03 May 2007 12:25:46 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <m28xc527sl.fsf@local.wv-www.com>
jayjuliano@gmail.com writes:
> On May 3, 8:40 am, - Bob - <uctra...@ultranet.com> wrote:
>>
>> I am hoping to avoid the "enter this displayed secret code"
>> mechanism as an annoyance for legit users.
>
> Utilize a 'Captcha' system.
That's what he's hoping to avoid.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 03 May 2007 18:06:28 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <59uj4kF2mdh94U1@mid.individual.net>
- Bob - wrote:
> I have some web forms that are getting hit by spammers sending spam
> into the system. They are simple forms, add your name, address, etc.
> Perl code handles the form, of course!
>
> I'd like to cut down on the spammers. I was thinking that perhaps I
> could check the person's IP against blacklists... but most of the
> blacklists I know of are mail servers, so I am not sure that is
> practical. I am hoping to avoid the "enter this displayed secret code"
> mechanism as an annoyance for legit users. But, I am open to
> suggestions on existing Perl based solutions (trails blazed before
> me!) or just pointers to good resources on programmable solutions to
> this issue.
>
> Thanks,
When a load of link spamming bots were hitting our contact forms I found
that ignoring any message with '</a>' or '[/url]' in got rid of 99% of the
crap.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 3 May 2007 10:17:44 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <1178212664.058928.176410@l77g2000hsb.googlegroups.com>
On May 3, 2:40 pm, - Bob - <uctra...@ultranet.com> wrote:
> I have some web forms that are getting hit by spammers sending spam
> into the system. They are simple forms, add your name, address, etc.
> Perl code handles the form, of course!
>
> I'd like to cut down on the spammers. I was thinking that perhaps I
> could check the person's IP against blacklists... but most of the
> blacklists I know of are mail servers, so I am not sure that is
> practical.
No, not really. These lists will often block all dynamic IP pools
which would block far too many ligit users.
> I am hoping to avoid the "enter this displayed secret code"
> mechanism as an annoyance for legit users.
Not to mention, in some jurisdictions, quite possibly grounds for a
law suit from visually impaired users.
------------------------------
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 V11 Issue 401
**************************************