[17962] in Perl-Users-Digest
Perl-Users Digest, Issue: 122 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 22 18:10:39 2001
Date: Mon, 22 Jan 2001 15:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980205013-v10-i122@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 22 Jan 2001 Volume: 10 Number: 122
Today's topics:
Newbie - whois script <deviant@ultra-deviant.removethisbit.com>
Re: Non Unix user needs help with File::Find <jdf@pobox.com>
Re: Perl and AOL. How is this possible? (G.A.D.Miles)
Re: Powerful Technique 3606 <elijah@workspot.net>
Re: Random Numbers with a Twist <rob@frii.com>
redirect system command to an array plandis98@my-deja.com
Re: redirect system command to an array (Craig Berry)
Re: redirect system command to an array (Eric Bohlman)
Re: Slightly Off Topic question, CG forms and hidden qu <joe+usenet@sunstarsys.com>
Re: Still Can't Get MIME Lite To Send Attachment... (Rand Simberg)
Re: ZIp Code Perl Program <chrisw.NOSPAM@dynamite.com.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Jan 2001 22:06:52 -0000
From: "Dave" <deviant@ultra-deviant.removethisbit.com>
Subject: Newbie - whois script
Message-Id: <1a2b6.10505$3d2.48629@news11-gui.server.ntli.net>
Below is my copy of a whois script - how do I change the background of the
page when it is processed - I need the background to be #666666.
Thanks in advance
Dave
--------------------------------------------------------------------------
#!/usr/bin/perl
$showdetail ="yes";
$scriptname ="whois.pl";
$filename = "../htm/our_services_domain.htm";
open(HTMLFILE,"$filename");
{ local $/; $htmlContent = <HTMLFILE> }
close(HTMLFILE);
#print "$htmlContent";
$htmlContent = "Content-Type: text/html\n\n" . $htmlContent;
@html = split(/<!--whois-->/, $htmlContent);
#checks for data entered in form
&get_data;
#if data is found here it will go off and do a whois else it will
display a blank form
if( $query{'fqdn'} eq "" ) {
print "$html[0]";
print ("<div align=\"center\"><p>Powered by <a
href=\"http\://www.chicagoSpace.net/\">chicagoSpace</a></div>");
print "$html[1]";
exit;
}
$availabletext="<font color='#ff0000'>is available</font>";
$fqdn= $query{'fqdn'};
# kill all whitespace
$fqdn =~ s/^\s+|\s*\n$//g;
# convert to lowercase
$fqdn=~tr/A-Z/a-z/;
#Remove everything leaving just letters, numbers and hyphens
$fqdn=~s/[^a-z0-9\-\.]//g;
#if ($checkthis=~/^\-/) { &warning("$line hyphen\(s\) removed,
domain names can't start with \-") }
$fqdn=~s/^\-+//; #kill leading hyphens
$fqdn=~s/\--+/-/g; #two hyphens next to each other is a no no,
convert to a single 1
$fqdn=~s/\-\././g; #kill trailing hyphens
use IO::Socket;
# Check For ilegal Charactares and display error message if need be
if ($fqdn =~
/\!|\"|\£|\$|\%|\^|\&|\*|\(|\)|\_|\=|\+|\#|\~|\||\/|\,|\;|\:|\@|\?|
\<|\>/ )
{
print "$html[0]";
&anerror;
print "$html[1]";
exit;
}
#display top of page
print "$html[0]";
#go and do the whois
&checkdomain;
#print the raw whois
if ($showdetail eq "yes")
{
print("$out");
}
#diplay the bottom of the page
print ("<div align=\"center\"><p> <a
href=\"http\://www.chicagoetools.com/chicagospace/main/htm/our_serv
ices_domain.htm\">Search for another Domain?</a></div>");
print "$html[1]";
exit;
sub checkdomain {
$server = $temp[1];
@pts = split(/\./, $fqdn);
if($pts[0] eq 'www' || $#pts > 2)
{
&show("","",$command,$input,"Only certain top level domains
are supported by this script. \nDo not include www when submitting
your request","Whois ");
exit;
}
$nnum = $#pts;
$domain = lc($pts[$nnum]);
# This works out what whois server to use. To add more just add new
lines below in the same format
%ext = (
'com','whois.crsnic.net',
'net','whois.crsnic.net',
'org','whois.crsnic.net',
'uk','whois.nic.uk',
);
$server = $ext{$domain} if ($ext{$domain} && !$server);
$server = 'whois.crsnic.net' if $server eq '';
#do the whois query.. notice no external whois prgram so should
work in NT
$sock = IO::Socket::INET->new("$server:43") || die &fail;
print $sock "$fqdn\n";
@output=<$sock>;
close $sock;
chop(@output);
foreach $x (@output)
{
if ($x =~ /Whois Server: whois./)
{
$homewhois=$x;$homewhois=~s/Whois Server: //;
$homewhois =~ s/^\s+|\s*\n$//g;
$out ="";
$sock = IO::Socket::INET->new("$homewhois:43") || die &fail;
print $sock "$fqdn\n";
while (<$sock>) {
$out = $out . $_ . "<br>";
}
close $sock;
goto FOUND;
}
if ($x =~ /No match/i or /No entries/i or /Not found/i or /No
Records/i or /not registered/i)
{
$available="yes";
}
}
foreach $x (@output){
$out = $out . $x . "<br>";
}
FOUND:
if ($available eq "yes")
{
print ("<p>$fqdn $availabletext<p>");
}
else
{
print ("<p>$fqdn is unavailable<p>");
}
}
# this will be where you enter your error message
sub anerror
{
print <<"EOZ";
<div align="center">
<h3>A domain name can only contain charactres A-Z, 0-9 and hyphens
(-)</h3><p>
</div>
EOZ
}
sub get_data
{
if (length ($ENV{'QUERY_STRING'}) > 0){
$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
hex($1))/eg;
$query{$name} = $value;
}
}
}
------------------------------
Date: 22 Jan 2001 15:20:43 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Non Unix user needs help with File::Find
Message-Id: <g0ibxrs4.fsf@pobox.com>
sjamiso@my-deja.com writes:
> Now you know what I'm trying to do, take a second look at the code and
> make suggestions.
The suggestions that I and another reader have made all still hold.
Good luck!
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Mon, 22 Jan 2001 20:44:19 GMT
From: usad1@gadnet.com (G.A.D.Miles)
Subject: Re: Perl and AOL. How is this possible?
Message-Id: <3a6c97a6.24467213@news.newsguy.com>
Gosh, this is hard work. As I mentioned in my original posting, I am
well aware that the script runs on the server, not the browser. Hence
my confusion. Equally, pedantic quibling aside, it seems not
unreasonable to say that the following script, when referenced from a
browser, takes you to a web site:
#!/usr/bin/perl
print "Location: http://www.gadnet.com/bplus\n\n";
That, when it's all stripped down, is what my banner exchange script
does, although obviously not to a fixed URL.
Thanks for the less agressive responses though. None have really set
me on the right path, but while my perl skills are adequate, my
language skills are clearly not, so I'll take the easy route and give
up.
------------------------------
Date: 22 Jan 2001 20:59:00 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Powerful Technique 3606
Message-Id: <eli$0101221543@qz.little-neck.ny.us>
In comp.lang.perl.misc, Bart Lateur <bart.lateur@skynet.be> wrote:
> zoycit@email.com wrote:
> >pmpmofcqxzgkvsvpobtjfurjdfxnjqmo
>
> This was the most sensible sentence in the whole post. ;-)
>
> Does anybody know how to write a regex that matches this kind of
> neonsense? You can easily recognize it by eye, but... is there really a
> pattern? At least 4 consonants in a row?
As others have said, that's not good enough. Here's a function I
used to use as part of a newsgroup moderation filter. $psuedotext
is a global scoring variable. Bigger numbers are less like
English. This function was looped over every line of the body,
and then added to the score if ($psuedotext/(lines-in-body))>0.1
That line triggers a 'strong psuedotext' warning.
For what it is worth, that subject just barely squeaks by this
5 point score penalty, from the same script:
# Five or six digit number at end of subject. Very spamish.
/\s\d\d\d\d\d\d?\s*$/
# Operates on body (^ and $ work)
sub scan_for_psuedotext
{
my $vowels;
my $obscure;
my $total;
my $perct;
my $myverbose = 1;
$_ = shift;
# First: ignore lines with URLs or email addresses
return if /\b(URL|https?|mailto):|\w+\@([\w-]*\.)+\w+/;
# Next ignore uuencoded/base64 stuff (it doesn't pretend to be text).
return if
m%^M[\020-\140]{60}$|^[A-Za-z0-9+/]{72}$%;
# Methodology: In normal English usage The frequencies of KQXJZ are
# at about 1.1% or all letters, while the vowels are at about 36.1%.
# (source http://144.118.28.202/class/insys300/LetterStatistics.html)
# Any line where these obscure letters are equal to or exceed vowels,
# and there are at least three of each group, is considered
# strong psuedotext. And line with at least twenty letters is weak
# psuedotext if fewer than 25% or more than 50% are vowels. Very
# weak psuedotext applies to any line meeting the above percentages,
# but has between six and nineteen letters.
$vowels = tr:AEIOUaeiou::;
$obscure = tr:KQZJZkqxjz::;
$total = tr:A-Za-z:: + 1;
if (($vowels > 2 ) and ($obscure > 2) and ($obscure >= $vowels)) {
$psuedotext += 2;
print "strong psuedo ($vowels:$obscure): $_\n" if $myverbose;
} else {
$perct = $vowels / $total * 100;
if ($total > 20) {
if (($perct < 25) or ($perct > 50)) {
$psuedotext ++;
print "weak psuedo ($perct): $_\n" if $myverbose;
}
} elsif ($total > 6) {
if (($perct < 25) or ($perct > 50)) {
$psuedotext += 0.5;
print "vweak psuedo ($perct): $_\n" if $myverbose;
}
}
}
}
Elijah
------
former alt.sex.stories.moderated moderator
------------------------------
Date: Mon, 22 Jan 2001 14:20:32 -0700
From: Rob Greenbank <rob@frii.com>
Subject: Re: Random Numbers with a Twist
Message-Id: <lm5p6t4b57pe7vlejs9mr0btvetek9mi5a@4ax.com>
On 20 Jan 2001 00:42:40 GMT, abigail@foad.org (Abigail) wrote:
>The hard part is deciding when to stop, that is, when is the set
>random enough?
Yup. I think your solution will work, but the randomness could be
nearly non-existent. It might be possible to create a situation where
a solution exists, but *only* one solution (ie. the points *have* to
be spaced evenly from corner to corner). A more likely situation
would be having a small number of solutions possible, in which case
the solution will not look very random.
Two thoughts. I'm not a mathematician, but I would guess it would be
possible to at least estimate of the probability of solving the
problem with each run. Then the person (or process?) could decide if
it was worth trying or not. If the probability was 50%, on average it
would take two attempt to solve the problem.
I also wonder if an algorithm could be contrived to dynamically
increase the size of the grid as needed. With that one could at least
generate the smallest possible grid based on the points already
chosen.
Maybe the best way is to add a rule that says if it isn't big enough
to guarantee a solution, regardless of the points chosen, then don't
even try.
Actually, I think the best solution (for me) is to be satisfied with
having had some stimulating thought and bow out of the thread. So,
everyone take care,
Rob
------------------------------
Date: Mon, 22 Jan 2001 21:21:06 GMT
From: plandis98@my-deja.com
Subject: redirect system command to an array
Message-Id: <94i87o$9l9$1@nnrp1.deja.com>
How do I redirect a system command to an array? For instance, I want
to get a list of files in a directory and it's sub directories so what
I do is do a system find command :
system("find $ARCHIVE_ROOT -name '*-arc' -print");
But how would I redirect the list generated from the system find to an
array?
One solution that I came up with would output the list to a file and
then read in the file and parse the list to an array? But this
wouldn't be the most efficient way.
thanks,
Peter Landis
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Mon, 22 Jan 2001 21:59:32 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: redirect system command to an array
Message-Id: <t6pba4ebsqv807@corp.supernews.com>
plandis98@my-deja.com wrote:
: How do I redirect a system command to an array? For instance, I want
: to get a list of files in a directory and it's sub directories so what
: I do is do a system find command :
:
: system("find $ARCHIVE_ROOT -name '*-arc' -print");
:
: But how would I redirect the list generated from the system find to an
: array?
print "Read the doc!\n" until $enlightened;
From the 'perldoc -f system' entry:
This is not what you
want to use to capture the output from a command,
for that you should use merely backticks or `qx//',
as described in the section on "`STRING`" in the
perlop manpage.
See how much faster and easier it would have been to read the doc, rather
than post to Usenet and wait around for some random person to answer (and
perhaps answer incorrectly or nonoptimally)?
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "The hills are burning, and the wind is raging; and the clock
| strikes midnight in the Garden of Allah." - Don Henley
------------------------------
Date: 22 Jan 2001 22:01:33 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: redirect system command to an array
Message-Id: <94iajt$3r0$7@bob.news.rcn.net>
plandis98@my-deja.com wrote:
> How do I redirect a system command to an array? For instance, I want
> to get a list of files in a directory and it's sub directories so what
> I do is do a system find command :
> system("find $ARCHIVE_ROOT -name '*-arc' -print");
> But how would I redirect the list generated from the system find to an
> array?
> One solution that I came up with would output the list to a file and
> then read in the file and parse the list to an array? But this
> wouldn't be the most efficient way.
It certainly wouldn't. The most efficient way, not only in terms of CPU
time, disk space, and memory, but also in terms of your time and the time
of the readers of this newsgroup, is for you to look at Perl's
documentation for system() (perldoc -f system), which will immediately
tell you that system() isn't what you want to use in this case and will
refer you to the documentation for the operator that you really *do* want
to use.
------------------------------
Date: 22 Jan 2001 14:09:29 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Slightly Off Topic question, CG forms and hidden query data fileds?
Message-Id: <m3bsszs8t2.fsf@mumonkan.sunstarsys.com>
stanb@panix.com (Stan Brown) writes:
> I am writing a perl CGI script. This script leads teh suer through a
^^^^^^^^
Is that "10 plaintiffs", "to sewer", or "the user"?
> serries of choices, each set of choices is based upon the prvious
> ones.
[...]
> My problem is that the forms callbacks to my script don't seem to be
> able to see the hidden data fields. I am puting them in the message
> to the server that draws the framest.
>
> Is this wrong?
Assuming that it ain't working, yes.
> Can this be made to work?
You might try putting the hidden fields inside the html contents of
each window instead of inside the "frameset message". But certainly
this has nothing to do with Perl.
> I'm using CGI.pm, if it matters.
Good, but I doubt that's causing the problem. Try a cgi newsgroup
for more/better help.
HTH
--
Joe Schaefer
------------------------------
Date: Mon, 22 Jan 2001 22:05:08 GMT
From: simberg.interglobal@trash.org (Rand Simberg)
Subject: Re: Still Can't Get MIME Lite To Send Attachment...
Message-Id: <3a6cadac.335992920@nntp.ix.netcom.com>
On Sun, 21 Jan 2001 15:06:54 GMT, in a place far, far away,
simberg.interglobal@trash.org (Rand Simberg) made the phosphor on my
monitor glow in such a way as to indicate that:
>I still can't get MIME Lite to actually attach a file. When I run the
>following:
>
>$msg = new MIME::Lite
> From =>$mailer,
> To =>$recipient,
> Subject =>'Contact Record Archive',
> Type =>'multipart/mixed';
>
> # Add parts (each "attach" has same arguments
>as "new"):
> attach $msg
> Type =>'TEXT',
> Data =>"The attached file contains
>your requested archive backup.";
> attach $msg
> Type =>'text/plain',
> Path =>"$data_directory/$file",
>
> $msg->send;
>
>I get an email message with the following body:
>
>******************************************************************
>
>Content-Disposition: inline
>Content-Length: 57
>Content-Transfer-Encoding: binary
>Content-Type: text/plain
>
>The attached file contains your requested archive backup.
>*******************************************************************
>
>But still no attachment. AFAIK, the path is valid. Does anyone have
>any idea what the problem might be?
Found the problem. Apparently, if it's of type text, it is just
embedded in the message body. In order to force it to an attached
file, it has to be some other type.
I set it to Type => 'application/octet-stream' and it worked just
fine...
************************************************************************
simberg.interglobal.org * 310 372-7963 (CA) 307 739-1296 (Jackson Hole)
interglobal space lines * 307 733-1715 (Fax) http://www.interglobal.org
"Extraordinary launch vehicles require extraordinary markets..."
Replace first . with @ and throw out the "@trash." to email me.
Here's my email address for autospammers: postmaster@fbi.gov
------------------------------
Date: Tue, 23 Jan 2001 09:50:01 +1100
From: "Chris W" <chrisw.NOSPAM@dynamite.com.au>
Subject: Re: ZIp Code Perl Program
Message-Id: <XP2b6.39$Eu5.1661@news0.optus.net.au>
"Phallicity" <phallicity_2000@yahoo.com> wrote in message
news:93vlcp$lm$1@nnrp1.deja.com...
> I am looking for a perl (cgi) script that will automatically enter a
> users city & state given a zip code
If this is for a internationally accessable service then _please_ don't
forget that the rest of the world (you know, the bit outside the USA) has
different requirements for zip codes (aka postcodes) and states or
provinces.
For Australian postcodes try:
http://www.whitepages.com.au/wp/search/pcode.jhtml
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 122
**************************************