[18968] in Perl-Users-Digest
Perl-Users Digest, Issue: 1163 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 20 06:10:31 2001
Date: Wed, 20 Jun 2001 03:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993031811-v10-i1163@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Jun 2001 Volume: 10 Number: 1163
Today's topics:
Re: how to validate email address <melorama@nospam.gov>
Re: HowTo: Run a command in backticks as root? <>
libwww question <msperrin@u.washington.edu>
Re: MAJOR perl bug <pne-news-20010620@newton.digitalspace.net>
Re: Memory Issues/File Slurping <goldbb2@earthlink.net>
Re: Newbie requests help with Net::Ping module to use a <buggs-clpm@splashground.de>
newbie requires some help <ravivarma@kernex.com>
Re: newbie requires some help <buggs-clpm@splashground.de>
Re: newbie SMTP problem <goldbb2@earthlink.net>
Re: Opinion on 'Mastering Algorithms with Perl' <EvR@compuserve.com>
Re: Removing ^M characters <josef.moellers@fujitsu-siemens.com>
Re: Removing ^M characters <p.m.spandler@bton.ac.uk>
Running Perl Scripts <osbornelee@hotmail.com>
Re: Running Perl Scripts <christian.meisl@tugraz.at>
Re: tail -f in a perl-program <goldbb2@earthlink.net>
Re: trying to optimize -> system call questions <goldbb2@earthlink.net>
Unix - NT problems.... <rajesha.c@in.bosch.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Jun 2001 05:58:48 GMT
From: Mel Matsuoka <melorama@nospam.gov>
Subject: Re: how to validate email address
Message-Id: <03e0jt4hdd0k6l5ilp64vvqflfdqiogke9@4ax.com>
On Tue, 19 Jun 2001 12:32:13 +0200, Philip Newton
<pne-news-20010619@newton.digitalspace.net> wrote:
>On 19 Jun 2001 00:58:09 -0700, h155@ms37.hinet.net (chih-chieh, Huang)
>wrote:
>
>> My idea is to check the domain name from email address, i.e.
>> if email=abc@abc.com
>> then, use ping or nslookup to check whether domain name (abc.com) is valid.
>>
>> In using "Ping", system's response will be "abc.com is alive" if this domain
>> does exist.
>
>Bad. For example, one of my addresses is Philip.Newton@datenrevision.de
>, which is certainly deliverable. But 'ping datenrevision.de' will fail
>because there is no host by that name. (Hint: MX vs A DNS RR)
Also bad: Many hosts simply do not accept ping requests for security reasons,
and as such you'll never see ping replies from hosts that are otherwise very
much alive and kicking.
Just for fun, try it on microsoft.com :) If your "validation" script relies on
ping replies, you'll basically shut thier entire domain out of whatever system
your script is a backend for. Then again, maybe that's not such a bad thing ;)
Other major hosts that appear to drop incoming ping packets:
earthlink.net
hotmail.com
aol.com
juno.com
As you can see, a very BAD idea.
Aloha,
mel
------------------------------
Date: 20 Jun 2001 00:50:11 -0500
From: Simon Devlin <>
Subject: Re: HowTo: Run a command in backticks as root?
Message-Id: <k1e0jtsfot9ifshu5vvoavl6v8bv0q9bj0@4ax.com>
Thanks to both of you for this, I'll try the suggestions. I take the
point about being careful with NMAP, but this is a tool for internal,
corporate use (which I agree doesn't remove the need for security, but
at least means it's not being fronted on an internet facing webserver)
Regards
On Wed, 20 Jun 2001 02:36:33 +0000 (UTC), see-sig@from.invalid (David
Efflandt) wrote:
>On Tue, 19 Jun 2001, Bruno Montagnac <bruno.montagnac@renault.com> wrote:
>> hi,
>>
>> it's typically an UNIX pb, not a Perl one...
>> if u want to run a process with root rights, u'll have to "give" the
>> binary to root (chown) & to activate the suid bit (chmod)
>> then, u can run the nmap binary from Perl under the apache user (the
>> process will still be owned by root)
>> remember to set acces rights on for the apache user (others +rx or with
>> ACLs may be)
>
>The suid bit is ignored by most systems, but you can probably get it to
>work by using 'suidperl' in the shebang line at the top instead of 'perl'.
>See 'perldoc perlsec' about untainting.
>
>> take care to nmap safety... or only give read/exec rights to apache user
>> (playing with a subdirectory set) to avoid everyone launch it...
>
>Probably should protect it with crypted password or web authentication.
>
------------------------------
Date: Tue, 19 Jun 2001 23:06:31 -0700
From: "M. Scholz" <msperrin@u.washington.edu>
Subject: libwww question
Message-Id: <Pine.A41.4.33.0106192303100.94310-100000@dante53.u.washington.edu>
I am trying to use CPAN, and when that didn't work , downloading the
tarball from sourceforge, for libwww. The problem is that it keeps
spitting this error at me from the `make test` command. Is there any way
to make the output more verbose, so I can see why? Or does anyone know
what the problem might be? The machine is a newly installed RH 7.1 box.
The error (the only one, I might add) is:
robot/rules-dbm.....FAILED test 8
Failed 1/13 tests, 92.31% okay
...
robot/rules-dbm.t 13 1 7.69% 8
Failed 1/22 test scripts, 95.45% okay. 1/287 subtests failed, 99.65% okay.
thanks
-Matthew Scholz
Where does Thinking end,
and Feeling ...
------------------------------
Date: Wed, 20 Jun 2001 10:53:23 +0200
From: Philip Newton <pne-news-20010620@newton.digitalspace.net>
Subject: Re: MAJOR perl bug
Message-Id: <81p0jto9pgvrh65ns728jr4unbm488521t@4ax.com>
Please don't stealth CC. Not all MUAs display a 'Newsgroup' line if
present (neither of the ones I use frequently do), so a line in the
beginning of the message indicating that it's a copy of a message that
was also sent to Usenet is polite.
On Wed, 20 Jun 2001 00:30:09 GMT, Bob Walton <bwalton@rochester.rr.com>
wrote:
> Philip Newton wrote:
> ...
> > perl -V should give you the version and, with ActivePerl, also the
>
> Actually, that's:
>
> perl -v
Did you try it? Both work. perl -V gives you more verbose output. I
wasn't sure that perl -v gives you the ActivePerl build number, so I
used -V. It turns out that -v gives you the information, too, but that
doesn't make -V wrong.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Wed, 20 Jun 2001 05:51:27 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Memory Issues/File Slurping
Message-Id: <3B30721F.AB175F58@earthlink.net>
Doug McGrath wrote:
>
[snip]
> One of things that's been bugging me in the original work that I had
> was the following:
>
> $line =~ m/\Gstrict;/;
>
> In this instance, $line contained the entire contents of a 25 MB
> repository file, and the previous matches had set pos($line) to one
> character (which was a space) before "strict;" occured in the string.
>
> According to "ps agxv" before and after the line, the memory usage of
> my script jumped 16 MB for this pattern match, and I'm at a loss to
> explain why.
Perhaps perl is allocating memory in chunks. It reached the end of
whatever it'd had allocated, then allocated another chunk... which
happened to be 16 MB.
> I could understand if there were wild cards and the regex engine had
> to build a huge tree of possible matches, but in this case, there's
> only one possible match with the anchor, and it seems like it should
> either succeed or fail immediately with only a few bytes built up into
> the match.
>
> It's clear to me that writing efficient regex's on files of this size
> require that I understand the process that the regex engine is going
> through, but it's also clear to me that I currently don't because I
> have absolutely NO explanation for the above behavior.
I'd offer more ideas, but I don't understand the internals of the
regexengine myself.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Wed, 20 Jun 2001 09:13:05 +0200
From: buggs <buggs-clpm@splashground.de>
Subject: Re: Newbie requests help with Net::Ping module to use as learning example...
Message-Id: <9gpiao$727$06$1@news.t-online.com>
Demitri Borg wrote:
> Would anyone care to maybe demonstrate how to use Net::Ping in an
> example script so that i might be able to better grasp the concept of
> how to load and use modules
>
> or maybe give info on where i can read up more on modules and how to
> use them...
>
> Any help is greatly appreciated.
On YOUR system command prompt try:
perldoc MODULE
man MODULE
explorer c:\perl\html\index.html
Ever wondered if software includes documentation?
The net:
http://cpan.search
http://groups.google.com
http://www.google.com/search?q=Perl+Documentation
http://www.perl.com/pub/v/documentation
http://learn.perl.org
http://perldoc.org
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html
They now have search machines and stuff too.
;-)
Buggs
------------------------------
Date: Wed, 20 Jun 2001 07:04:11 GMT
From: "ravivarma" <ravivarma@kernex.com>
Subject: newbie requires some help
Message-Id: <LVXX6.9625$Up.280621@sea-read.news.verio.net>
hi
i have a linux system installed redhat 6.0
perl5.005
mod_pel-1.25
libwww-perl-5.53
libnet-1.0703
URI-1.12
MIME-Base64-2.12
HTML-Parser-3.25
Digest-MD5-2.13
my apache enable all the modules.
I m trying to keep an statement PerlRequire /path but it coming out with a
statement saying that
perhaps mis-spelled or defined by a module not include in the server
configuration
1) how to enable the PerlRequire in httpd.conf ??
i tried the --enable-module=perl --enable-shared=perl but it doesnt work
thank U in advance
ravivarma
------------------------------
Date: Wed, 20 Jun 2001 09:19:46 +0200
From: buggs <buggs-clpm@splashground.de>
Subject: Re: newbie requires some help
Message-Id: <9gpinc$ag3$00$1@news.t-online.com>
ravivarma wrote:
> hi
>
> i have a linux system installed redhat 6.0
> perl5.005
> mod_pel-1.25
> libwww-perl-5.53
> libnet-1.0703
> URI-1.12
> MIME-Base64-2.12
> HTML-Parser-3.25
> Digest-MD5-2.13
--snip--
> 1) how to enable the PerlRequire in httpd.conf ??
> i tried the --enable-module=perl --enable-shared=perl but it doesnt work
It's a bug in you processor.
See
http://perl.apache.org
http://httpd.apache.org
http://www.modperl.com
Buggs
------------------------------
Date: Wed, 20 Jun 2001 05:31:19 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: newbie SMTP problem
Message-Id: <3B306D67.1E1B0644@earthlink.net>
Thing wrote:
>
> i dont know why this code doesnt work, does anyone see anything wrong
> with the code ?
You "use" a whole bunch of modules you don't actually need or call on,
you don't have -w, you don't have strict, you are trying to manually
perform a SMTP transaction when there already exists a module to do so,
and you aren't checking the returned text from the smtp server.
> if i telnet to my isp, and run the commands, it works, but if i use
> this code nothing happens and i get no errors.
Sure you do. You just don't see them.
> the $CRLF i am trying to make a carriage return line feed so that it
> executes the commands.
That's not the purpose of CRLF.
> *Note i changed the server and email address.
>
> #!/perl/bin/perl.exe
use strict;
use warnings;
> use CGI qw/:standard/;
This isn't a CGI. Why do you have this?
> use DBI;
You aren't using any SQL or other database stuff. You don't need this.
> use CGI;
This is almost the same as use CGI qw/:standard/; Why do you have it?
> use CGI::Carp qw(fatalsToBrowser);
Why do you have this?
> use IO::Socket;
Well, you have one thing sortof right. But really, you should be using
Net::SMTP for the whole thing. I'll give an example down below of how
you would do that. Meantime, I'll show you more of the things you're
doing wrong with this script.
> $CRLF = "\015\012";
IO::Socket already defines CRLF. Why do you redefine it?
> my $sock = new IO::Socket::INET (PeerAddr => 'smtpout.something.net',
Using the indirect object syntax can lead to wierd errors in production
code. Use:
IO::Socket::INET->new
instead of:
new IO::Socket::INET
> PeerPort => '25',
> Proto => 'tcp');
The protocol defaults to tcp, you can leave that out. Also, since you
are using a named protocol, you should give that name along with the
port.
my $sock = IO::Socket::INET->new
PeerAddr => 'smtpout.something.net',
PeerPort => 'smtp(25)';
> if ($sock)
> {
> print "my god, its full of stars";
> }
Instead of testing that the socket was created, you should be testing if
it wasn't created.
unless( $sock ) {
print "Failed to create tcp connection to ".
"smtpout.something.net:smtp(25): $!";
exit;
}
> print $sock "HELO insurance.com$CRLF
> MAIL From:<thing@insurance.com>$CRLF
> RCPT To:<guy@aol.com>$CRLF
> DATA$CRLF
> This was from Perl$CRLF
> .$CRLF
> QUIT$CRLF" || die "didnt work";
> close($sock) || die "didnt work";
You've doubled all the newlines. There's the $CRLF newline, followed
by the actual newline which you've quoted. The following might work
better:
for((
"HELO insurance.com"
"MAIL From:<thing@insurance.com>"
"RCPT To:<guy@aol.com>"
"DATA"
"This was from Perl"
"."
)) { print $sock $_, $CRLF }
And lastly, you should output what the smtp server sends back:
print STDOUT <$sock>;
Regardless, this is NOT the best way to write a mailing program.
You should use the sendmail program (see perlfaq9), Mail::Internet,
Mail::Mailer, Mail::Send, Net::SMTP, Mail::Sender or Mail::Sendmail. I
would advise reading the documentation of all of them before deciding
which to use.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 23:01:40 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: Opinion on 'Mastering Algorithms with Perl'
Message-Id: <9gpam7$80m$1@suaar1ac.prod.compuserve.com>
The book is good, but is clearly an academic approach, as opposed to the
approach of Learning Perl or Programming Perl.
Regards,
Rick Evans
------------------------------
Date: Wed, 20 Jun 2001 08:19:34 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Removing ^M characters
Message-Id: <3B304076.FBB90B06@fujitsu-siemens.com>
isaacs wrote:
> =
> In article <3B26717D.BE551C2E@alcatel.com>, "Thanh Q Lam"
> <thanh.q.lam@alcatel.com> wrote:
> =
> > Does anyone know how to remove the "^M" characters at the end of each=
> > line which without removing uppercase M that may have in the same lin=
e
> > in perl?
> >
> > Examples:
> > This is a book^M
> > That is a Mango^M
> >
> > If I use tr -d in unix which will remove all "M"
> =
> If you use tr '\r' '\n' in unix it will work.
> =
> Result:
> This is a book
> That is a Mango
Probably not, since the ^M (\r) precedes an ("invisible") ^J (\n).
You'll end up with two ^J (\n) in a row:
This is a book
That is a Mango
Better use the OP's suggestion of "tr -d '\r'".
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 20 Jun 2001 08:37:45 +0100
From: paul spandler <p.m.spandler@bton.ac.uk>
Subject: Re: Removing ^M characters
Message-Id: <3B3052C9.E6963C49@bton.ac.uk>
Hi
Thanh Q Lam wrote:
>
> Does anyone know how to remove the "^M" characters at the end of
> each line which without removing uppercase M that may have in
> the same line in perl?
This is something that I often find in a mixed Win32 / Unix environment.
I usually use the perl flavour of dos2unix:
http://history.perl.org/oneliners/filters/dos2unix.html
Failing that, sed works rather nicely too:
cat infile | sed 's/.$//' > outfile
...but only if the last line of text in infile ends with a cr/lf. If
not, you'll trash the last line of text :-(
You can also grab a dos2unix binary from the 'net. I think you can get a
Win32 version here:
http://www.gik.uni-karlsruhe.de/~zippelt/lehre/unixdos_utils.html
There's a *nix verison here:
ftp://metalab.unc.edu/pub/Linux/utils/text/dos2unix-3.0.tar.gz
HTH
Paul
--
Paul Spandler 44 (0)1273 642925
Systems Manager
IT Research Institute
University of Brighton
------------------------------
Date: Wed, 20 Jun 2001 09:54:25 +0100
From: "Lee Osborne" <osbornelee@hotmail.com>
Subject: Running Perl Scripts
Message-Id: <993027342.25774.0.nnrp-13.c2de1f0e@news.demon.co.uk>
Hi guys,
Sorry if this is an easy one. I think I have read all the FAQS.
How do I run a perl/cgi script as the administrator via a web browser?
Thanks in advance,
Lee.
------------------------------
Date: Wed, 20 Jun 2001 11:12:33 +0200
From: Christian Meisl <christian.meisl@tugraz.at>
Subject: Re: Running Perl Scripts
Message-Id: <5286813.CHz00ifERb@famvtpc59.tu-graz.ac.at>
Lee Osborne wrote:
> How do I run a perl/cgi script as the administrator via a web browser?
1. You definitely do not want to do such things!
2. A quick and diry solution:
chown root yourfile
chmod o+x yourfile
chmod +s yourfile
Regards
Christian
--
Christian Meisl
Department for Chemical Apparatus Design, Particle Technology and Combustion
Graz University of Technology
------------------------------
Date: Wed, 20 Jun 2001 03:27:51 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: tail -f in a perl-program
Message-Id: <3B305077.14E58B3@earthlink.net>
Konstantinos Agouros wrote:
>
> Hi,
>
> I want to read line-like with <DESCRIPTOR> from logfiles. Currently I
> do something like 'open(DESK,"tail -f /var/log/messages|")' to stay
> life on the logfile. Is this the most efficient way to do this? Since
> I don't want to loose the <> using select (the system call) might not
> be the best idea or is there something I am missing completely?
#! perl -w
use strict;
use IO::Select;
my $select = IO::Select->new;
my %foo;
for my $fn ( @ARGV ) {
unless( open my $fh, "<", $fn ) {
warn "Couldn't open(FH, <, $fn): $!, skipping\n";
next;
}
use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
unless( my $flags = fcntl($fh, F_GETFL, 0) and
fcntl($fh, F_SETFL, $flags | O_NONBLOCK) ) {
warn "Couldn't make nonblocking: $!, skipping\n";
}
$select->add( $fh );
(my $tag = $fn) =~ s!.*/!!;
$foo{"$fh"} = [ $tag, 0, "" ];
}
while( my @ready = $select->can_read ) {
for my $fh (@ready) {
my $select_one = IO::Select->new $fh;
my ($tag, $curpos, $remainder) = @$foo{"$fh"};
seek $fh, $curpos, 0;
do {
defined( my $line = <$fh> ) or last;
$curpos = tell( $fh );
unless( chomp $line ) {
$remainder .= $line;
last;
} else {
$line = $remainder . $line;
$remainder = "";
}
print "$tag: $line\n";
} while( $select_one->can_read(0) );
$foo{"$fh"}[1,2] = ($curpos, $remainder);
}
}
This code is untested.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Wed, 20 Jun 2001 04:38:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: trying to optimize -> system call questions
Message-Id: <3B306107.ECD63375@earthlink.net>
Shon wrote:
>
> I have perl script which calls many other scripts via system(). I am
> re-writing these to be used as modules by the main script. I thought
> that this would improve my performance by not creating new processes.
> In reality the execution time has slowed down by 20%. Any ideas why
> the system call is so much faster?
It depends on what they do, and how you're calling them.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Wed, 20 Jun 2001 15:34:17 +0530
From: "Rajesha" <rajesha.c@in.bosch.com>
Subject: Unix - NT problems....
Message-Id: <9gps8k$dsl$1@proxy.fe.internet.bosch.com>
Hello,
I'm working on a project in which my perl script has to search for
particular keyword in a file (of size 2.9+ MB, 85000+ lines) & replace some
data matching that keyword
stored in array. On NT, i have installed ActivePerl version 5.003_07.
Execution in this version takes only 3 minutes. But on Unix ( solaris os, I
have perl version 5.005_03) same script is taking 20+ minutes.
I'm using grep command to fetch/search the keywords from array/file. I guess
that this grep is slowing the processing in UNIX. Why is this problem
occurs? Is there any solution or alternate solution to solve my problem?
I'm using following statements to fetch the data from file or array.
I'm searching $var_label in global array.
@line_val=grep{/[\s]*$var_label/} @globaltypes::array_details;
#@line_val = grep{/[\s]*$var_label/} <MAPDATA>;
I tried hash. Eventhough hash is faster in search, it is very slow in
inserting the data into hash.
Can anyone help me to make the code run faster in unix?
regards,
Rajesha.
+ Robert Bosch India Limited,
123, Industrial Layout, Hosur Road,
Koramangala, Bangalore 560 095, India
( office : +91-80-508 1256
Res : +91-80-652 7225
BCN Hotline : 9628 - 3328
mailto:rajesha.c@in.bosch.com
------------------------------
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 1163
***************************************