[6368] in Perl-Users-Digest
Perl-Users Digest, Issue: 990 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 21 20:17:09 1997
Date: Fri, 21 Feb 97 17:00:21 -0800
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, 21 Feb 1997 Volume: 7 Number: 990
Today's topics:
/dev/ptmx and Comm.pl problem (Tyger)
Re: [Q] Array and system <tchrist@mox.perl.com>
Re: [Q] removing lines in a file.. (Tad McClellan)
a2p awk-to-Perl question ... <tevans@cas.org>
Re: Checking for redirection (file input) (J. Mello)
Executing a DOS command in PERL? <bob_calvert@hp.com>
Re: futur de perl et java-script <tsv@gold.cs.umanitoba.ca>
Getting positions in matched string <owt1@cornell.edu>
installing PERL on UNIX through WIN95 sy (Hayes, Dianne)
Looking for Interactive Training CD-ROM for Perl <rokahn@hplb.hpl.hp.com>
Overloading builtin functions <cedar.w.milazzo@boeing.com>
Re: Passing command line parameters (Clay Irving)
Pel5, BSDI, Libwww and various other critters. (Dustin Andrews)
Perl system function ahd HP-UX versions <phillip.green@citicorp.com>
Re: PERL/NT development environment/guru setup out ther (Kermit Tensmeyer)
Re: piping data through unix command <hub@club-internet.fr>
Re: POP3 modules (Chris Nandor)
problem with dbmopen (Jason Powell)
Re: PROGRAM: how to check for nice/valid email address (Gerald Oskoboiny)
Re: PROGRAM: how to check for nice/valid email address <twpierce+usenet@mail.bsd.uchicago.edu>
Re: Regexp to do minimal email validation <rra@cs.stanford.edu>
Re: Regexp to do minimal email validation (James Wetterau)
Re: regexp: comma-delimited (csv) with "" inside <dbenhur@egames.com>
Re: relative directory address vs absolute <rra@cs.stanford.edu>
Setuid scripts and $0 - Arg! <chris@ixlabs.com>
Re: simple new question! (Kevin Buhr)
Re: unlink on Win95 ("John Dallman")
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Feb 1997 20:49:51 GMT
From: tyger@fiat.gslis.utexas.edu (Tyger)
Subject: /dev/ptmx and Comm.pl problem
Message-Id: <5el1pf$4ft@geraldo.cc.utexas.edu>
Hey there folks.
I'm running Comm.pl on a solaris 2.4 box. I'm employing the Comm.pl
library to operate an interactive shell tool that works much like passwd.
It parses a data file and takes the parsed information and feeds it to the
shell util. I prototyped it with a sample data file yesterday and it
works like a charm.
But today I ran it with a "real" date file that is quite a bit larger,
and it parses fine, and does it's thing (correctly) for a while, but now
it will error out part way through the job saying:
Could not open /dev/ptmx, No such device at /usr/local/lib/perl5/Comm.pl
line 652.
Ok, I do in fact have /dev/ptmx - but I'm very sketchy on what it does.
>From what I can speculate, it looks like the larger amount of information
that is fed to to the interactive shell util (using the Comm.pl
functions), which results in more iterations of the Comm.pl subroutines,
are eventually "overrunning" this device file to the point that when
Comm.pl goes to open it again, it can't.
After the data is parsed, a foreach loop passes the data (in the form of
variables) off to a subroutine that calls the Comm.pl functions that
operate the shell util. I've tried putting a "sleep" call in the
subroutine to give it a chance to catch it's breath, but it does not work.
I am using the "expect", "interact", "open_proc" and "close_it"
subroutines from Comm.pl.
So, to anyone who understands the workings of this device file - is there
any way to "flush" it, or make it un-busy? Can I add a call to clear up
this device between each iteration of this shell util subroutine? The
script itself works fine, but the increased amount of data confuses this
device and it errors out on me.
If anyone can offer any insight I'll give you my first born.
Thanks y'all!
T'gr
--
-------------------- Tyger - http://www.eden.com/~tyger --------------------
------------ Flight of the seabirds - scattered like lost words ------------
------------------------------
Date: 21 Feb 1997 21:04:09 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: [Q] Array and system
Message-Id: <5el2k9$dpo$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Wouter de Boer <wouter.deboer@pi.net> writes:
:Hello,
:
:Sorry, but I see only a little part of the message, so I try it for the
:thirth time
:
:I've two questions:
:
:I have a module which returns three array, but when I want to use the
:second array from my module is it empty, because all the values are
:strored in the first array. The second and the thirth array are empy.
:I use this code:
Did you not read what perlsub has to say about this?
Pass by Reference
If you want to pass more than one array or hash into a function--or
return them from it--and have them maintain their integrity, then
you're going to have to use an explicit pass-by-reference. Before you
do that, you need to understand references as detailed in the perlref
manpage. This section may not make much sense to you otherwise.
Here are a few simple examples. First, let's pass in several arrays to
a function and have it pop all of then, return a new list of all their
former last elements:
@tailings = popmany ( \@a, \@b, \@c, \@d );
sub popmany {
my $aref;
my @retlist = ();
foreach $aref ( @_ ) {
push @retlist, pop @$aref;
}
return @retlist;
}
Here's how you might write a function that returns a list of keys
occurring in all the hashes passed to it:
@common = inter( \%foo, \%bar, \%joe );
sub inter {
my ($k, $href, %seen); # locals
foreach $href (@_) {
while ( $k = each %$href ) {
$seen{$k}++;
}
}
return grep { $seen{$_} == @_ } keys %seen;
}
So far, we're using just the normal list return mechanism. What happens
if you want to pass or return a hash? Well, if you're using only one of
them, or you don't mind them concatenating, then the normal calling
convention is ok, although a little expensive.
==> Where people get into trouble is here:
==>
==> (@a, @b) = func(@c, @d);
==> or
==> (%a, %b) = func(%c, %d);
==>
==> That syntax simply won't work. It sets just @a or %a and clears the @b
==> or %b. Plus the function didn't get passed into two separate arrays or
==> hashes: it got one long list in @_, as always.
If you can arrange for everyone to deal with this through references,
it's cleaner code, although not so nice to look at. Here's a function
that takes two array references as arguments, returning the two array
elements in order of how many elements they have in them:
($aref, $bref) = func(\@c, \@d);
print "@$aref has more than @$bref\n";
sub func {
my ($cref, $dref) = @_;
if (@$cref > @$dref) {
return ($cref, $dref);
} else {
return ($dref, $cref);
}
}
It turns out that you can actually do this also:
(*a, *b) = func(\@c, \@d);
print "@a has more than @b\n";
sub func {
local (*c, *d) = @_;
if (@c > @d) {
return (\@c, \@d);
} else {
return (\@d, \@c);
}
}
Here we're using the typeglobs to do symbol table aliasing. It's a tad
subtle, though, and also won't work if you're using my() variables,
because only globals (well, and local()s) are in the symbol table.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Historically speaking, the presence of wheels in Unix has never precluded
their reinvention."
--Larry Wall
------------------------------
Date: Fri, 21 Feb 1997 16:02:21 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [Q] removing lines in a file..
Message-Id: <d16le5.o73.ln@localhost>
Eric D. Carter (ecarter@a-lincoln.hnet.uci.edu) wrote:
: Just finished checking out the newsgroups, website & man pages.. but I
: haven't found what I'm looking for. If someone could point me in the
: right direction I would appreciate it.
: I want to remove a single line from a file. So far, I have only been
: able to do this by opening an existing file, writing to a temp file
: and renaming when I'm done. Is it possible to simply open a file and
^^^^^^^^^^^^^^
: remove a $_ (entire line..) without using a second file?
^^^^^^^^^^^^^^^^^^^^^^^^^^^
On Unix filesystems, the general answer is: No.
Some variations:
1) open for read and write ( open (FILE, "+<filename")... )
a) read it all in
b) do what you want to the in-memory file
c) seek() back to the beginning of the file
d) write it all back from memory
2) you can do real in-place edits if you are replacing the _exact_
same number of characters, which isn't what you need.
3) use Perl's -i command line switch (perlrun man page) to do all the
temp file create, write, move back over original for you. It will
still be using a second file, but you won't have to program it
to do so...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 21 Feb 1997 16:18:44 -0500
From: "Troy A. Evans" <tevans@cas.org>
Subject: a2p awk-to-Perl question ...
Message-Id: <330E10CD.144D@cas.org>
Hello,
I am trying to convert 'awk' scripts to Perl with the 'a2p' tool.
I keep getting a "syntax error" for a trivial 'awk' construct, the
concatenation operation. Here's my 'awk' script:
BEGIN {
a = "1234"
b = "-"
c = "5678"
}
$1 ~ /^[a-zA-Z]/ {
isssn = a b c
print "<sgmltag>" isssn "</sgmltag>"
next # Go to next input line.
}
and when I try to convert it to Perl, here's what I get:
$ a2p awkscript
syntax error in file awkscript at line 8
Translation aborted due to syntax errors.
It's choking on line 8, the concatenation operation:
isssn = a b c
which is a trivial 'awk' construct appearing everywhere in my scripts.
The debugging output of 'a2p' is not helpful. What gives?
Troy Evans
Chemical Abstracts Service
tevans@cas.org
More info:
$ file `which a2p`
/usr/perl5.1/bin/a2p:
ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not
stripped
CPU: Sun Sparcstation 5.
OS: Sun Solaris 5.4
------------------------------
Date: 21 Feb 1997 22:54:47 GMT
From: kingjamm@u.washington.edu (J. Mello)
Subject: Re: Checking for redirection (file input)
Message-Id: <5el93n$igd@nntp1.u.washington.edu>
Thanks for all the help... I didn't realize that there were the -<flag>
test operators in Perl... I guess that I'd better read the Camel a little
more carefully... At any rate, thanks for all the help.
-James
In article <Pine.GSO.3.95q.970221115934.4498G-100000@kelly.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On 20 Feb 1997, J. Mello wrote:
>
>> I'm currently having a hard time trying to find out if a file is being
>> redirected via a "<" into my shell. For instance...
>>
>> foo.perl < testfile
>
>> I've tried searching for a "<" in @ARGV, but for some reason,
>> arguments to your shell don't include pipes or redirections.
>
>I think you've got that backwards. The shell takes the pipes and
>redirections and opens them for your process. Your process starts with
>three filehandles opened for free, STDIN, STDOUT, and STDERR. But your
>script isn't supposed to be able to tell whether it was invoked with the
>command above or this "useless use of cat" contest entry:
>
> cat testfile | foo.perl
>
>... because your process is not the command. It's just foo.perl.
>
>> If the testfile is being redirected in, I want to just process it, but
>> otherwise I want to interactively call an editor so the user can enter
>> the data in.
>
>I think you want to find out whether STDIN is coming from a keyboard or a
>disk, right? Try using -t, like this:
>
> if (-t) {
> # Start up the editor
> } else {
> # Just read in the file directly
> }
>
>Hope this helps!
>
>-- Tom Phoenix http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com PGP Skribu al mi per Esperanto!
>Randal Schwartz Case: http://www.lightlink.com/fors/
>
------------------------------
Date: Fri, 21 Feb 1997 20:46:15 GMT
From: Bob Calvert <bob_calvert@hp.com>
Subject: Executing a DOS command in PERL?
Message-Id: <330E0997.7F8E@hp.com>
I have a DOS command, that I would like to execute from a perl script
running as a CGI program on NT. How do I do this?
For example, the program is: E:\cgi-bin\myprog.exe and I want to
redirect input into this program from a file E:\temp\myfile.
At a DOS prompt, I simply type:
E:\cgi-bin\myprog < E:\temp\myfile
and it works fine. Any idea how I do this in a Perl script?
e-mail always appreciated.
Bob Calvert
roc@atl.hp.com
------------------------------
Date: 21 Feb 1997 18:24:05 -0600
From: Varadarajan <tsv@gold.cs.umanitoba.ca>
Subject: Re: futur de perl et java-script
Message-Id: <qavi7llmca.fsf@gold.cs.umanitoba.ca>
Tom Christiansen <tchrist@mox.perl.com> writes:
>
> [courtesy cc von diese posting sent to citado autor via email]
>
> En comp.lang.perl.misc, Dominique BAGOT <Dominique.BAGOT@cetp.ipsl.fr>
>
> :Bonjour a tous,
> : A votre avis, Perl est-il condamne ?
> : Je veux dire : Java script ne le remplacera-t-il pas ?
>
> Quo vadis, Dominique? Non erat his locus!
For the benefit of people who dont understand this language, would a
English translation be posted??
Varadarajan.T.S.
------------------------------
Date: 21 Feb 1997 17:32:07 -0500
From: Owen Taylor <owt1@cornell.edu>
Subject: Getting positions in matched string
Message-Id: <lzzpwxvli0.fsf@cu-dialup-0819.cit.cornell.edu>
Here's a little problem I've been trying to figure out:
Given a string representing a perl regex with inserted slashes,
$pat = "((AB|AAB)/)*C/DD?"
and a string to match against,
$str = "AABABCD"
Find the string the results from inserting slashes into positions
in $str which correspond to those position in $pat with slashes,
with correspondence being defined by how $pat would match $str,
without the slashes. (Ignoring degenerate cases where $pat includes
things like "/+").
I'm fairly convinced that there is no way of doing this except
for inserting /'s into all possible positions in $str, but
I'm hoping that somebody has a clever idea. Thanks,
Owen
------------------------------
Date: Fri, 21 Feb 1997 16:43:17 -0500
From: dianne.hayes@systecinc.com (Hayes, Dianne)
Subject: installing PERL on UNIX through WIN95 sy
Message-Id: <1997Feb21.162000.1205.102842@smtp.systecinc.com>
I run on a WIN95 system and access files on the UNIX box that I work with
through a Windows-based FTP program (and also through Telnet). I have a
CD-ROM with perl on it (packaged with the book _UNIX Programming Tools_
by Eric Foster-Johnson; don't worry Randal -- I also have the llama book,
but it didn't have a disk with it), but I'm not sure how I go about
installing it on this UNIX box that is not at my site.
Can I install this across my FTP connection?
Any ideas?
If it helps any:
It's version 5.003
The readme file is dated 1/29/96 and begins with
Perl Kit, Version 5.0
Copyright 1989-1996, Larry Wall
The install file is dated 6/24/96 and is the
"Build and Installation guide for perl5"
>From what I've read, all of the directions seem to assume that I am in
the UNIX environment already and accessing my CD-ROM. Unfortunately, I
am not in that situation.
I consider myself a pretty technical person, so I should be able to
follow any ideas that are sent my way, but I can't seem to get any
further with these files.
Thanks for any help that you can be.
:) D
Dianne Hayes
(another perl hacker wannabe)
------------------------------
Date: Fri, 21 Feb 1997 11:54:07 -0700
From: Rocky Kahn <rokahn@hplb.hpl.hp.com>
Subject: Looking for Interactive Training CD-ROM for Perl
Message-Id: <330DEF4F.374F@hplb.hpl.hp.com>
Looking for Interactive Training CD-ROM for Perl
Any advice?
Rocky Kahn
rokahn@hplb.hpl.hp.com
------------------------------
Date: Fri, 21 Feb 1997 23:08:13 GMT
From: Cedar Milazzo <cedar.w.milazzo@boeing.com>
Subject: Overloading builtin functions
Message-Id: <330E2ADD.202@boeing.com>
Hi. Does anyone out there know of a way to override a function such as
the "open" function? I'm trying to create a library file which, when
included, will always append a directory name in front of any file
opened from any of my scripts.... Any help would be greatly
appreciated. (please email me at cwm@premier1.net)
Thanks
Cedar Milazzo
------------------------------
Date: 21 Feb 1997 19:37:07 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Passing command line parameters
Message-Id: <5elf3j$45d@panix.com>
In <5eftq3$t7j@concorde.ctp.com> jvenu@ctp.com (Jagadeesh Venugopal) writes:
>In article <Pine.LNX.3.95.970219122727.4676B-100000@wauug.erols.com> Joe Tseng <jtseng@wauug.erols.com> writes:
>>I checked with my blue camel book but I could not find the answer.
>>
>>script directly on the command line. Right now I have parameters being
>>passed as:
>> $foo = <STDIN>;
I'd do: chomp($foo = <STDIN>);
(I'm lazy)
>Maybe your Camel is missing Page 445, Getopt::Long?
Yeah, but some folks are intimidated|can't install modules -- Sad, but true.
In this case, I'd use:
chomp($foo = $ARGV[0]);
--
See the happy moron,
He doesn't give a damn, Clay Irving N2VKG
I wish I were a moron, clay@panix.com
My God! Perhaps I am! http://www.panix.com/~clay
------------------------------
Date: Fri, 21 Feb 1997 23:47:48 GMT
From: dustin@icefog.polarnet.com (Dustin Andrews)
Subject: Pel5, BSDI, Libwww and various other critters.
Message-Id: <2157cd$e2f30.371@PolarNet>
Keywords: bsdi dynamic IO libwww
I have dug through all of the docs trying to figure this out. That has
not gotten me anywhere. I did stop and read all of the Larry Wall quotes.
That help keep me from going crazy. (what does that say?)
At any rate here is my problem:
I need to write a program that polls a server via Telnet. Then
sends some commands and parses the output eventually I need to poll web
servers too but not yet. I can parse output with my eyes closed (well not
really) but the real problem is the telnet session.
Thus far in my Perl excursions everything that seemed hard had a
library that does the hard stuff so I thought I would go load libwww.
Libwww for Perl 5 complains that I need to make a dynamic loading
Perl -OR- link IO statically into it. So I have fiddled with Perl trying
to compile a dynamic version for BSDI 2.1 and have been unsuccessful. I
cant figure out where the heck to load the IO module statically.
So I need help. Is libwww the solution I am looking for? Or
should I be looking into something else? If so what? If not how can I
make a dynamic loading Perl or link in IO?
TIA,
--
Dustin Andrews, 907 457-4929 -- Home Page: www2.polarnet.com/~dustin
PolarNet, Inc. -- Tech support, Apache, Perl, Majordomo
Email: webdev@polarnet.com -- Web Develpment: www2.polarnet.com/webdev
"Spam: Capitalism or the Spawn of Satan?" - Anon
------------------------------
Date: Fri, 21 Feb 1997 15:48:14 -0500
From: "Jairo A. Medina" <phillip.green@citicorp.com>
Subject: Perl system function ahd HP-UX versions
Message-Id: <330E0A0E.1EB6@citicorp.com>
Hola:
I have this perl code:
$result = system("ls");
print $result;
inside a big program.
If I execute it in
HP-UX mahogany A.09.04 E 9000/816
it works great. I got $result = 0
if I execute the same program in
HP-UX cherry B.10.10 A 9000/811
I got $result = -1 but if I make a program with only those 2 lines it
works fine.
I'm not doing anything between both lines.
Does somebody know something about this problem?
Thanks in advance,
--
===============================================================
Jairo Medina Phone: (609) 727-4600
Bluestone Pager:1-800-232-1934
1000 Briggs Road Email: jairo@bluestone.com
Mt. Laurel, NJ 08054
Web: http://www.bluestone.com/
===============================================================
------------------------------
Date: Fri, 21 Feb 1997 21:20:11 GMT
From: kermit@cnad.dl.nec.com (Kermit Tensmeyer)
Subject: Re: PERL/NT development environment/guru setup out there ?
Message-Id: <5el3f0$omh@vivaldi.inoc.dl.nec.com>
In article <330d1891.3353662@news.alt.net>, gniemcew@dti.net wrote:
>Hi !
>
>It's probably a "dream on!" type of question, but here it goes anyway:
>is there an integrated development environment for PERL/NT4/Win95 ? I
>am thinking a nice (color coding) editor in one window, interpreter
>stdout in another, and still a script's output in yet another ? PERL
>debugger with variable trace ?
Emacs gives the color options, multiple windows and the perl -d runs under
the debugger,
Emacs runs under Win95/NT and Unix
look in the standard places....
Kermit Tensmeyer NEC InterNet Operations Centre (INOC)
kermit@cnad.dl.nec.com Dallas, Texas
------------------------------
Date: Fri, 21 Feb 1997 19:13:06 +0100
From: Nicolas Hubert <hub@club-internet.fr>
To: Klaus Foerster <klausf@mucsun.sps.mot.com>
Subject: Re: piping data through unix command
Message-Id: <330DE5B2.717C8A5C@club-internet.fr>
Suppose you want to get the output of a Unix command (like "cat
some_file" for instance), but don't need to pass stuff to its std input,
then you can use something like :
open COMMAND, "cat some_file |" or die "bla bla bla\n";
while (<COMMAND>) {
do_something_with($_);
}
close COMMAND;
If you need to pass data to a command's stdin and read from its stdout,
you can try using open2, but that's kind of dangerous because it can
result in a deadlock. See the Camel book about that. I've written a
small printing filter that writes to GhostScript and fetches the output
using open2, but I don't have it here at home. I can post it or e-mail
it to you on Monday if you need more info.
Then, there's also open3, and socketpair combined with fork (something
in the Perl faq about that, I think).
Hope this helps,
Nicolas
Klaus Foerster wrote:
>
> Hi folks,
>
> I'd like to send data through a unix command.
>
> I imagine it like this
>
> - perl program starts and forks.
> -> now there are two perl processes
> - Process 1 should generate data and send it to a unix command
> (e.g. sort, its just an example I know that perl can sort as well)
> - Process 2 should read the output of this unix command
>
> So process 1 generates data for a unix program.
> and finishes afterwards.
> process 2 will read all the data and postprocess it.
>
> Does anyone have a small example?
>
> Thanx in advance.
>
> bye
>
> --
> Klaus Foerster
------------------------------
Date: Fri, 21 Feb 1997 16:57:41 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: POP3 modules
Message-Id: <pudge-ya02408000R2102971657420001@news.idt.net>
In article <5el17t$69m@neon.btinternet.com>, J.Olsen@btinternet.com (John
Olsen) wrote:
#I want to use perl to read mail. I know there is Mail::POP3Client and
#there is also Net::Pop3.
#
#Which should I use or doesn't make any difference?
No comment to be made no which is better, but I can say I had trouble
getting Mail::POP3Client to work, and Net::Pop3 worked first time no
problem.
#================================================================
I guess of all my uncles, I liked Uncle Cave Man the best. We
called him Uncle Cave Man because he lived in a cave and every
once in a while, he'd eat one of us. Later we found out that he
was a bear.
--Jack Handey
Chris Nandor pudge@pobox.com
PGP Key 1024/B76E72AD http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10 1F F7 7F 13 81 80 B6 B6
------------------------------
Date: 21 Feb 1997 22:22:23 GMT
From: jpowell@badlands.NoDak.edu (Jason Powell)
Subject: problem with dbmopen
Message-Id: <5el76v$kvu@daily-planet.nodak.edu>
I am having trouble with dbmopen on a Red Hat Linux 3.0.3 machine. I
have a program that works on another unix platform, but on this one it
dies on the dbmopen command. Reading the man page, I found a bit that
says, dbmopen (1) has been superseded by the tie() function and (2)
produces a fatal error if the system has neither DBM or ndbm. I can't
find either one of these on my system and I am thinking this is the problem.
Either using tie instead or installing DBM or ndbm would be fine with me,
but I can't figure out how to use tie from the man page and don't know
where to find or how to install the two files. Any help would be
appreciated.
Jason Powell
------------------------------
Date: 21 Feb 1997 20:51:51 GMT
From: gerald@cs.ualberta.ca (Gerald Oskoboiny)
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <5el1t7$bfm@scapa.cs.ualberta.ca>
Dean Pentcheff <dean@tbone.biol.sc.edu> writes:
>duplanti@enstb.enst-bretagne.fr (DUPLANTIER Bastien) writes:
>> where could i get the Tom Christiansen's article about this subject?
>
>To save you the trouble: you can't. There is no way to check for the
>validity of an email address except by sending the mail and seeing if
>it gets there. No way.
I'm not sure I have anything to add to this thread, but just to
contribute another data point:
I wrote something that verifies addresses by sending e-mail with
a verification code that must be entered into a form on the Web.
For the first while it didn't do any kind of syntax validation
before sending the verification code, and I got a lot of bounces
with stuff like "1234,56789@compuserve.com" or "user1234" specified
as the address.
So I added a couple regexp checks before sending that message,
and the number of bounces dropped. The regexps I use are:
&complain if $recipient =~ /[^A-Za-z0-9@\.+%#!_-]/;
&complain if $recipient !~ /.@.+\../;
Yes, these will incorrectly flag some e-mail addresses as being
invalid when they are valid, but this has processed 27,241 addresses
since it was put into use in June 1996, and I can only recall two
people ever writing to me saying their e-mail address didn't pass
the syntax check. One had a '#' character in their address, the
other was '!'; I added them both to my regexp.
This has caught at least 425 invalid addresses in that time,
most of them seeming to be either typos or from people who
just don't know what their e-mail addresses are.
Gerald
--
Gerald Oskoboiny <gerald@cs.ualberta.ca> http://ugweb.cs.ualberta.ca/~gerald/
------------------------------
Date: Sat, 22 Feb 1997 00:22:37 GMT
From: Tim Pierce <twpierce+usenet@mail.bsd.uchicago.edu>
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <E5zADq.4oG@midway.uchicago.edu>
[courtesy cc of this posting sent to cited author via email]
In article <5eijlj$p43$1@csnews.cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> wrote:
>In comp.lang.perl.misc,
> jon@amxdigital.com (Jonathan Peterson) writes:
>
>:#Program gathers an email address, does as much
>:#checking as is reasonable, and adds it to a list.
>
>Did you not see this program?
>
>#!/usr/bin/perl
>#
># addrcheck - mail address checker
Them what doesn't like 24K regexps can also use <URL:ftp://bsdac.
uchicago.edu/pub/twp/devil.shar>. It isn't in Perl, but hey, you
can't always have everything.
--
Support the Hawaii Equal Rights Marriage Project: call 1-900-97-MARRY ($5/call)
------------------------------
Date: 21 Feb 1997 13:56:05 -0800
From: Russ Allbery <rra@cs.stanford.edu>
Subject: Re: Regexp to do minimal email validation
Message-Id: <qum4tf5zuve.fsf@cyclone.stanford.edu>
Eli the Bearded <usenet-tag@qz.little-neck.ny.us> writes:
> While you can't check for sure, here is/was my quick and dirty check
> for a reasonable From: line in mail:
> /^From:.*\s<*([^ <>@]*)@([^ <>@.]+)[^ <>@]*[.]([a-z][a-z]|com|net|org|edu\
> |gov|mil|int|arpa|firm|store|web|arts|rec|info|nom|[0-9]+]*)(> *| .*)$/i
> It could be better. It will accept <<<bozo@bo...zo>, although it will
> catch <bozo@.bo.zo>. For my purposes it helpe to be able to catch
> <bozo@bozo.com> type addresses, hence the parenthesis. With the
> exception of the bozo@bozo test, I don't think there is any valid
> @-style address for which that will create a false positive.
This is valid under RFC 822:
From: rra(Russ Allbery@somewhere)@cs(hi mom!).stanford.edu
--
Russ Allbery (rra@cs.stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: 21 Feb 1997 18:34:52 -0500
From: jwjr@panix.com (James Wetterau)
Subject: Re: Regexp to do minimal email validation
Message-Id: <5elbes$hra@panix.com>
In article <Matthew.Healy-2002971159050001@pudding.med.yale.edu>,
Matthew D. Healy <Matthew.Healy@yale.edu> wrote:
>...
>> *can't*. You can't. There's no point. Send the mail, and if it gets
>> to them, it's the right address. <fred&barney@stonehenge.com> is a
>> valid address, and would have been falsely rejected by your regexp.
>
>I just tried it, and it worked the _SECOND_ time, because the first
>time I forgot to put single quotes around the address, causing Unix
Double quotes work just fine with my (bash) and many other shells.
--
James Wetterau, Jr. |
jwjr@panix.com (h) | <--- But some people call me Maurice
jwjr@name.net (w) |
------------------------------
Date: Fri, 21 Feb 1997 15:02:47 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Curt Siffert <siffert@shell.wco.com>
Subject: Re: regexp: comma-delimited (csv) with "" inside
Message-Id: <330E2997.5629@egames.com>
Curt Siffert wrote:
> I've been reading Jeffrey's Owl book and there is extensive work
> with the CSV example - If you're making a comma-delimited file
> by exporting from Excel, for instance, it will put quotes around
> phrases with commas in them. His example takes that into account
> so it won't split on those internal commas. However, what of phrases
> that also have quotes?
>
> Earvin "Magic" Johnson yields "Earvin ""Magic"" Johnson"
>
> The code I'm using:
> push(@new, $+) while $text =~ m{
> "([^\"\\]*(?:\\.[^\"\\]*)*)",? # groups the phrase inside the quotes
> | ([^,]+),?
> | ,
> }gx;
> push(@new, undef) if substr($text,-1,1) eq ',';
>
> This unfortunately treats "Earvin ", "Magic", and " Johnson" as three
> separate fields. I've been trying to figure out a way to make the
> first regexp alternative skip over a "" but I'm getting crossed up
> somewhere. I don't necessarily need to switch the "" to a " while
> I'm matching; I can just do that in the push statement. But I need
> a regexp that can successfully process:
>
> "Earvin ""Magic"" Johnson"
> """Magic"" Johnson"
> (and)
> "Earvin ""Magic"""
Well, I wrestled with this a few months ago too. I punted on
coming up with a regexp to handle the embedded quotes and
just wrote some code. Chances are good that the code is
as efficient as a single regexp might be anyway. When I have
more time I might document this and wrap it up as a module
(Text::CSV ?).
Here's a pair of subroutines that does what you want:
sub parse_csv_tok {
local $_ = shift;
my $tok = '';
s/^\s+//;
return () if $_ eq ''; # exhausted all tokens
if (s/^"//) { # quoted token
my $embed = '';
do {
$tok .= $embed; # add embedded " (except first time
$embed = '"'; # subsequent loops use embedded "
s/^(.*?)"//; # grab up to next "
$tok .= $1;
} while (s/^"//); # keep grabbing if next is "
s/^\s*,//; # strip whitespace and , seperator
} else { # unquoted token
s/^(.*?)\s*,//; # grab up to next seperator
$tok = $1;
}
return ($tok,$_);
}
sub parse_csv_line {
my $line = shift;
my $tok;
my @tokens = ();
push(@tokens,$tok) while (($tok,$line) = parse_csv_tok($line));
return @tokens;
}
$test = qq[ 123, hello world , "foo", """hi, there""", """""",] .
qq["Earvin ""Magic"" Johnson", """Magic"" Johnson","Earvin
""Magic"""];
print join("\n",parse_csv_line($test)),"\n";
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"Don't run away. We are your friends." O-
------------------------------
Date: 21 Feb 1997 13:39:03 -0800
From: Russ Allbery <rra@cs.stanford.edu>
To: wade@demographics.com
Subject: Re: relative directory address vs absolute
Message-Id: <qum914hzvns.fsf@cyclone.stanford.edu>
[ Posted and mailed. ]
Wade Leftwich <wade@demographics.com> writes:
> Is there a fairly easy way to convert relative directory addresses (like
> ../../mydir/myfile.txt) to absolute ones (like
> /dir1/dir2/dir3/mydir/myfile.txt)?
use Cwd;
chdir $dir;
$absolute_dir = cwd;
Make the operating system do the work for you.
--
Russ Allbery (rra@cs.stanford.edu) <URL:http://www.eyrie.org/~eagle/>
------------------------------
Date: Fri, 21 Feb 1997 14:06:20 -0800
From: Chris Schoenfeld <chris@ixlabs.com>
Subject: Setuid scripts and $0 - Arg!
Message-Id: <330E1C5C.2C3F@ixlabs.com>
AHhh!
I have a program which is executed by sendmail, and needs to be setuid.
It also needs to know it's scriptname.
Unfortunately, $0 gets boned (/dev/fd4?? - what does it think it's a
floppy drive?) when running setuid on Solaris, and sendmail doesn't seem
to spawn a shell which sets $ENV{'_'}.
This is a big time bug - it would seem like $0 should be false or
undefined if Perl can't figure out it's scriptname.
--
Chris Schoenfeld
IX Development Laboratories
Santa Rosa, California
(707)-543-8030 Ext. 12
------------------------------
Date: 21 Feb 1997 17:08:04 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: simple new question!
Message-Id: <vbabu9dzrjf.fsf@mozart.stat.wisc.edu>
m9418@abc.se (Jonas Bofjall) writes:
>
> Now here is my first two questions:
>
> 1. how do I change all occurences of "a" to "b", all "c" to "de" and
> all "g" to "ijkl" in a string? I guess it's done with the y/.../
> but HOW? I currently do it with several r/.../ (I think it was 'r'?)
> anyways, I guess that's not the correct way.
"y/.../.../" is only useful for character-by-character translations.
Though it *can* do deletion and squashing, it can't replace single
characters with longer strings the way you want it to.
Using a sequence of "s/.../.../" statements is certainly a sensible
method, but there's more than one way to do it. The coolest method I
can come up with off the top of my head is illustrated by the
following script:
#! /usr/bin/perl -w
%foo = ("a" => "b",
"c" => "de",
"g" => "ijkl");
$fookeys = join("|",keys %foo); # same as $fookeys = "a|c|g";
$_ = "a great test case";
print "BEFORE: $_\n";
s/$fookeys/$foo{$&}/g;
print "AFTER: $_\n";
That "s/.../.../" statement buried in there is just one of the many
reasons Perl is like cartoon music.
> 2. this code, shouldn't it work??:
> $abc = TRUE;
> if (abc) { print "this won't print!" }
I think you meant to write "$abc" in the second line instead of "abc":
if you use "abc", it's interpreted as the *string* "abc", and nonempty
strings are "true", so you'll always see the output. However, even
the "corrected" program:
$abc = TRUE;
if ($abc) { print "this *will* print!\n" }
works fine for me.
Maybe you could post a complete script that illustrates the problem?
Kevin <buhr@stat.wisc.edu>
------------------------------
Date: Fri, 21 Feb 1997 21:17:01 GMT
From: jgd@cix.compulink.co.uk ("John Dallman")
Subject: Re: unlink on Win95
Message-Id: <E5z1sD.3ot@cix.compulink.co.uk>
gt1535b@acmey.gatech.edu (The next Pele) wrote:
> What about '.' and '..'? Should I use unlink for those or should I use
> rmdir instead? The documentation for Perl says that rmdir should only
> be used on an empty directory. Is a directory empty if it only has '.'
> and '..' in it?
Err, yes. . and .. are special references to the directory itself and to
its parent directory. You can't delete them by themselves, and if you
could you'd mess up the disk. A directory with only . and .. in it may
indeed be deleted with rmdir.
John Dallman, jgd@cix.co.uk. A micro-FAQ on things I keep getting asked:
#!perl is at ftp://.../CPAN/ports/msdos/tips-tricks/hbp_403.zip, BigPerl
for MS-DOS can be found in CPAN via http://www.perl.com, Perl for NT/Win
95 can be found at http://www.activeware.com, with an excellent FAQ file
at http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html and
no, I don't have the slightest idea what's wrong with your CGI script.
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
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 V7 Issue 990
*************************************