[10757] in Perl-Users-Digest
Perl-Users Digest, Issue: 4356 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 4 01:07:25 1998
Date: Thu, 3 Dec 98 22:00:42 -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 Thu, 3 Dec 1998 Volume: 8 Number: 4356
Today's topics:
Re: Can standard Perl functions be overloaded ? (Ilya Zakharevich)
Re: Converting HTML tag and attribute case - Regular Ex (brian d foy)
CVS-utils/improvements for backups & distributed reposi <tobias@shark.td.org.uit.no>
Re: DB handles, best approach? <garethr@cre.canon.co.uk>
Re: Directory permission. (Ronald J Kimball)
Re: Does crypt() act differently in different versions? (Ronald J Kimball)
Re: Excel Spreadsheets, Perl, CGI and Linux <newspost@morlock.net>
Re: Fast way to produce block of random bytes? (Larry Rosler)
Re: Fast way to produce block of random bytes? (Ilya Zakharevich)
Re: How to use relatives directory in MacPerl vx Unix? (Kevin Reid)
Re: Is it possible to mix locale and Perl? (Ilya Zakharevich)
Re: Is it possible to mix locale and Perl? (Martien Verbruggen)
Re: Is it possible to mix locale and Perl? (Ilya Zakharevich)
Re: localtime () - perl's bug ? <sugalskd@netserve.ous.edu>
Re: New idiom? <rick.delaney@shaw.wave.ca>
nobody wants a new struct tm (was Re: localtime () - pe <Russell_Schulz@locutus.ofB.ORG>
Re: NT perl and mail <erich@orator.usma.edu>
Re: NT perl and mail (Martien Verbruggen)
Re: Perl to awk? <Russell_Schulz@locutus.ofB.ORG>
pkzip files with Compress::Zlib?? <ernie_oporto@mentorg.com>
Re: Question about =~ <garethr@cre.canon.co.uk>
Re: Regex question (Sam Holden)
regex: anchor or comma miko@idocs.com
Re: regex: anchor or comma (Martien Verbruggen)
SDBM search script <darrensweeney@eswap.co.uk>
Re: string to array (Ronald J Kimball)
the Unix epoch is not the beginning of time (was Re: lo <Russell_Schulz@locutus.ofB.ORG>
Re: usage of $_ within nested loops <garethr@cre.canon.co.uk>
Re: usage of $_ within nested loops <uri@sysarch.com>
Re: variable inside variable (Ronald J Kimball)
Re: wantarray() question. <rick.delaney@shaw.wave.ca>
Re: Why is "... @foo ..." occasionally a syntax error? (Ronald J Kimball)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Dec 1998 05:25:03 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Can standard Perl functions be overloaded ?
Message-Id: <747rnf$sfi$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@op.net>],
who wrote in article <747dr0$4ju$1@monet.op.net>:
> >1. Can either A or M redefine the (say) the open() function,
> >so that when B calls open(), it is another open() in A or M
> >that is called ?
>
> It depends on the function.
Correct.
> But no, you can't redefine `open'.
Of course you can. (Btw, one can judge this by colorization in CPerl mode.)
As I noted it on p5p a year ago, there are 2 or 3 exceptions to the
rule below due to misprints in Perl source, but
you can override anything which is not special-cased lexically.
Ilya
------------------------------
Date: Thu, 03 Dec 1998 21:13:06 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Converting HTML tag and attribute case - Regular Expression help
Message-Id: <comdog-ya02408000R0312982113060001@news.panix.com>
In article <36658063.C181C7AC@fh-karlsruhe.de>, Dirk Kaufmann <kadi0012@fh-karlsruhe.de> posted:
> in order to give compression tools a better chance doing their job
> you should prefer to set tags down case.
huh? are you missing a smiley, or couldn't you wait for april?
let's remember that lowercase needs more bits than uppercase according
to ASCII.
> this might be important in future if scripts are sent through slow network
> areas
> in the consumer market. I think of sattelite links for handys and tv. the
> pure
> mass of this "future users" might cause a significant slow down on net
> transfers,
oh yeah. plain text really hogs the network. forget about images,
audio, video, and telephony.
> and always remember: you can write better code than any generator !
well, some people might. haven't met too many of them though ;)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 04 Dec 1998 04:38:16 +0100
From: Tobias Brox <tobias@shark.td.org.uit.no>
Subject: CVS-utils/improvements for backups & distributed repositories
Message-Id: <xn6emqgfufr.fsf@shark.td.org.uit.no>
I'm considering writing perl scripts or modifying cvs giving support
for keeping backups in the best possible way. However, I don't want to
reinvent the wheel - so I'm wondering if this, or something similar
might exist. I'd also like some feedback; Is there anybody else that
might be interested if I write those scripts? Do you have opinion on
my ideas? Is this just a waste of time, or are those ideas so
brilliant they should even be incorporated in the next version of CVS?
Very shortly, I want to write something like:
cvs -d :local:/usr/local/cvsroot updatemirror :pserver:backup@backup.my.domain:/usr/local/cvsroot
cvs updatemirror :pserver:mylogin@cvs-site.at.other.side.of.earth:/usr/local/cvsroots/myproj
cvs -d :local:/usr/local/cvsroots/anotherproject mirror :pserver:mylogin@cvs.anotherproject.org:/usr/local/cvsroots/
cvs rawbackup - | gzip -c9 > /dev/tapedevice
cvs restorebackup - < /dev/tapedevice
cvs chksumtst chksumfile
cvs outdateundo <backup-repository> <revision(s)(range)>
More detailed, my proposal is to create commands (or scripts) doing:
* Chksum export
Creates a control file with all revisionnumbers and checksums.
* Chksum check
Checks if "immutable" data (log-entries and old revisions) are
currupted. Might or might not react at outdated (deleted) revisions.
(the chksumtst command as used above is ment to first check, then export)
* Exporting backup files (as in "rawbackup" above)
Creates a differential file containing data that might be used to
update the ,v-files.
* Importing backup files (as in "restorebackup" above)
Reads files of the format above, and builds an up-to-date repository
My idea is to either stream compressed backup files to a proper
storage media (like a tape), or to have a backup CVS repository (at a
backup server or at another disk) - or both. A backup/mirror cvs
pserver should never allow anything else than importing backup
files.
The concept having a backup repository might also be used to provide
mirroring of CVS-sites. The mirrors would be read-only, though. The
concept could however be extended to a truely distributed, global CVS
environment. In a truely distributed, global CVS environment each cvs
server would have a repository of projects beeing followed locally -
and the development in the repository would be a local branch. At
regular intervals, the branches should be merged with neighbouring CVS
servers.
* Undo outdates (deletements) of old revisions
The usefulness of this command is obvious in a distributed environment
- we like to have some of the advantages by having a repository
locally, but we don't want to pay the price regarding disk space, so
we keep outdating anything but the latest versions of the files. But
suddently we'd really like to have revision 1.14 anyway.
--
TobiX In a world without fences, who needs gates?
http://www.td.org.uit.no/~tobias/
------------------------------
Date: Thu, 3 Dec 1998 19:33:06 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: DB handles, best approach?
Message-Id: <si7lw981hp.fsf@cre.canon.co.uk>
frogsmock@my-dejanews.com wrote:
> I am setting up a site that uses Apache, mod_perl, and PostgreSQL (I
> am using the DBI module to talk to PostgreSQL). My question is, what
> is the most efficient approach to use in creating/tearing down the
> database handles?
It's almost always best to open one connection to your database per
Apache child, then ensure that all mod_perl handlers and CGI scripts run
by Apache::Registry use that connection. An easy way to re-use
connections without rewriting your scripts is to use Apache::DBI.
>From the documentation for Apache::DBI:
When loading the DBI module (do not confuse this with the
Apache::DBI module) it looks if the environment variable
GATEWAY_INTERFACE starts with 'CGI-Perl' and if the module
Apache::DBI has been loaded. In this case every connect request
will be forwarded to the Apache::DBI module. This looks if a
database handle from a previous connect request is already stored
and if this handle is still valid using the ping method. If these
two conditions are fulfilled it just returns the database
handle. If there is no appropriate database handle or if the ping
method fails, a new connection is established and the handle is
stored for later re-use.
The current version of Apache::DBI can be fetched from
http://www.perl.com/CPAN/modules/by-module/Apache/ApacheDBI-0.81.tar.gz
--
Gareth Rees
------------------------------
Date: Thu, 3 Dec 1998 23:35:29 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Directory permission.
Message-Id: <1djhfqa.5a4ug0pquz7oN@bos-ip-1-110.ziplink.net>
Christian H. Knudsen <webmaster@bluegalaxy.hypermart.net> wrote:
> My problem is that the script (naturally) isn't able to chmod
> the dir to 777 because of the 700 permission!
If your script could chmod the directory to 777 and back, it would
presumably have the access to just create the files without ever having
to change the directory's permissions.
What you have here is a design problem, not an implementation problem.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Thu, 3 Dec 1998 23:35:30 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Does crypt() act differently in different versions?
Message-Id: <1djhfvm.1gcispsk3it4wN@bos-ip-1-110.ziplink.net>
Xnera <nospam.xnera@cyberenet.net> wrote:
> Here is my test:
> if ( crypt($entered_pw, substr($onfile_pw, 3 , 2) ) eq $onfile_pw) )
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Why are you using characters from the middle of the string as the salt,
instead of the first two characters? I don't see how this ever could
have worked.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Thu, 3 Dec 1998 23:39:07 -0500
From: "Steven Morlock" <newspost@morlock.net>
Subject: Re: Excel Spreadsheets, Perl, CGI and Linux
Message-Id: <BMJ92.155$dF2.591368@lwnws01.ne.mediaone.net>
According to the documentation for OLE::Storage it comes
with a utility called 'herbert' that converts simple MS Excel
documents to HTML.
http://wwwwbs.cs.tu-berlin.de/~schwartz/perl/
Steve
--
Foliage Software Systems
aka The Nerd Farm
http://www.foliage.com
------------------------------
Date: Thu, 3 Dec 1998 21:36:45 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Fast way to produce block of random bytes?
Message-Id: <MPG.10d114c3f345bcd498993d@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <F3Eus4.8u5@RnA.nl> on Thu, 3 Dec 1998 22:36:04 GMT,
Gerben_Wierda@RnA.nl <Gerben_Wierda@RnA.nl> says...
> I would like to produce a block of 1024 random bytes. I cannot just use rand
> and() and add it to a string, because it will get added as a number, which
> means only bytes with values [0-9] will be used. I currently use
> $chunk .= pack( "L", rand( 2**31));
> until the $chunk is long enough. But this seems pretty slow. Is there a way
> to just get the bytes of rand() added to a string without them being
> interpreted and added as a number?
You can use the chr function to convert a number to a character.
$chunk = join "", map chr(rand 1 << 8), 1 .. 1024;
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 4 Dec 1998 05:54:02 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Fast way to produce block of random bytes?
Message-Id: <747tdq$3b$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<Gerben_Wierda@RnA.nl>],
who wrote in article <F3Eus4.8u5@RnA.nl>:
> I would like to produce a block of 1024 random bytes. I cannot just use rand
> and() and add it to a string, because it will get added as a number, which
You cannot use rand() because it is not random. Until perl reads from
/dev/random, the maximum you can expect is to get 2, maybe 4 random
bytes from Perl.
Hope this helps,
Ilya
------------------------------
Date: Fri, 4 Dec 1998 00:47:45 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: How to use relatives directory in MacPerl vx Unix?
Message-Id: <1djaxyx.yy4zr9mti05cN@slip166-72-108-203.ny.us.ibm.net>
Jean-Marc Piuze <jmp@mlink.net> wrote:
> I want to relative directory like "../" in Unix. I want my perl script run
> on Unix platform as well as a Mac platform.
>
> Can you help me.. Any answer? What to read? Where to look?
Just double the colon:
$path = '::a file in the parent folder';
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 4 Dec 1998 05:20:28 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Is it possible to mix locale and Perl?
Message-Id: <747res$sam$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Martien Verbruggen
<mgjv@comdyn.com.au>],
who wrote in article <lWG92.57$MF3.251@nsw.nnrp.telstra.net>:
> PS. You know that perl is locale sensitive? If you set your correct
> locale, perl will know what sort of characters are part of your
> alphabet.
>
> # perldoc perllocale
Stop spreading this disinfo around! Perl has no viable locale support.
There is a *kludge* "use locale" which may - by coincidence - work in
some situations. But it is nothing more than a coincidence.
Try mixing 'use locale' with 'use Text::ParseWords'.
Ilya
------------------------------
Date: Fri, 04 Dec 1998 05:40:35 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Is it possible to mix locale and Perl?
Message-Id: <nBK92.100$MF3.257@nsw.nnrp.telstra.net>
In article <747res$sam$1@mathserv.mps.ohio-state.edu>,
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> [A complimentary Cc of this posting was sent to Martien Verbruggen
> <mgjv@comdyn.com.au>],
> who wrote in article <lWG92.57$MF3.251@nsw.nnrp.telstra.net>:
>> PS. You know that perl is locale sensitive? If you set your correct
>> locale, perl will know what sort of characters are part of your
>> alphabet.
>>
>> # perldoc perllocale
>
> Stop spreading this disinfo around! Perl has no viable locale support.
>
> There is a *kludge* "use locale" which may - by coincidence - work in
> some situations. But it is nothing more than a coincidence.
>
> Try mixing 'use locale' with 'use Text::ParseWords'.
As far as I am aware, perl itself is fine (as long as the OS can deal
with it, and the right stuff is installed), some modules may not be.
If that notion is incorrect, I suggest that you submit a few
documentation patches for perl.
I can't really find much in the documentation for the locale pragma or
perllocale that provides any justification for your reaction.
Again: if you feel that perl is so bad at it, you should submit some
documentation patches.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: 4 Dec 1998 05:57:09 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Is it possible to mix locale and Perl?
Message-Id: <747tjl$7v$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Martien Verbruggen
<mgjv@comdyn.com.au>],
who wrote in article <nBK92.100$MF3.257@nsw.nnrp.telstra.net>:
> In article <747res$sam$1@mathserv.mps.ohio-state.edu>,
> ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> > Stop spreading this disinfo around! Perl has no viable locale support.
> >
> > There is a *kludge* "use locale" which may - by coincidence - work in
> > some situations. But it is nothing more than a coincidence.
> >
> > Try mixing 'use locale' with 'use Text::ParseWords'.
>
> As far as I am aware, perl itself is fine (as long as the OS can deal
> with it, and the right stuff is installed), some modules may not be.
Wrong. Perl is not fine, this is why modules cannot do a lot.
> If that notion is incorrect, I suggest that you submit a few
> documentation patches for perl.
Like this?
=head1 NAME
locale - pragmatic module to blah....
=head1 DESCRIPTION
Do not use this module, currently the whole concept of locale support
in Perl is broken.
1/4 ;-)
Ilya
------------------------------
Date: 4 Dec 1998 05:56:02 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: localtime () - perl's bug ?
Message-Id: <747thi$rud$1@news.NERO.NET>
Jarkko Hietaniemi <jhi@alpha.hut.fi> wrote:
: Russ Allbery <rra@stanford.edu> writes:
:> Jarkko Hietaniemi <jhi@alpha.hut.fi> writes:
:>
:> > Definitely. I hope whoever designed the contents of struct tm feels
:> > really ashamed. There are at least three bad decisions. (1) The year
:> > has no good reason [1] to be -1900'ed. (2) The month has no good reason
:> > to be -1'ed [2]. (3) If the month is -1'ed, why not the day of the
:> > month?
:>
:> > [1] "the seconds since 1900-01-01 fit better into a X-bit integer
:> > than the seconds since 1-01-01" is not a good reason. The library
:> > should worry about such details, the user shouldn't be punished
:> > for poor library implementation.
:>
:> It's worse than that, of course. Everything else uses seconds since 1970.
: If you count ANSI C time_t as "everything"...but the "seconds since"
: is not universally counted from 00:00:00 1970-01-01. VMS uses some
: random-looking-date in 1858 (*) and AFAIK MacOS uses the 1900.
: (*) it's not random, it's actually good astronomical math.
Ah, Nov 17, 1858. A wonderful date.
And VMS' native time format is a quadword counting 100ns ticks, too. We
don't worry about integer overflow until some time after 30K AD. (Though
well before that we'll have to deal with the Y10K problem, but there'a
already an SPD in with TCFKAD to fix that. We've got 8000 years--why worry
now, right? :)
If anybody really has a need, it is possible to convert VMS quadword times
into Unix epoch seconds completely in perl (and thus on any platform)
without losing any bits. (At least for dates up through 3000) I can post
or mail the code to anyone who's really interested
Dan
------------------------------
Date: Fri, 04 Dec 1998 05:01:27 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: New idiom?
Message-Id: <36676E5B.A5F6B1A4@shaw.wave.ca>
Sean McAfee wrote:
>
> This is what I did:
>
> %hash = ( foo => { bar => 5 }, baz => { bletch => 10 } );
> while ((my $a, local *b) = each %hash) {
> while (my ($c, $d) = each %b) {
> print "$a: $c => $d\n";
> }
> }
>
> This code runs fine without -w, but I get the above-mentioned warning
> when I add it. I neglected to mention my environment in my original
> article, but I'm using 5.005_02 on Solaris 2.6.
I should have mentioned mine when I asked since I'm still using Perl
Classic (5.004_04). That obviously makes all the difference since I get
no warning when running the above code. I suppose the warning was added
because you can't undef a file handle?
> For a project I'm working on, I wanted to create tied hashes
> that would act like normal hashes, but would retrieve from a (large)
> hash of default values when a nonexistent key was given:
>
> %default = ( a => "b", c => "d", e => "f", ... );
> %param = ( g => "h" );
> print $param{"g"}, $param{"a"}; # prints "hb"
>
> This was easy enough to do:
>
> package Parameters;
> use Tie::Hash;
> @ISA = 'Tie::StdHash';
> sub FETCH {
> my ($self, $key) = @_;
> exists $self->{$key} ? $self->{$key} : $::default{$key};
> }
>
> But I ran into deep-recursion trouble when I tried something like
> this:
>
> while ((my $host, local *default) = each %hosts) {
> print $default{"key not present in %{ $hosts{$host} }"};
> }
>
> Fortunately, this problem is easily solved, and in the process of
> solving it I learned something I never realized before about typeglob
> aliasing:
>
> *foo = *bar;
> $bar = 123;
> { local *bar; print $foo; }
>
> This prints 123, indicating that after *bar is localized, *foo
> continues to refer to *bar's original typeglob. So, all I had to do
> to solve my problem was this:
>
> package Parameters;
> *default = *::default;
> sub FETCH {
> my ($self, $key) = @_;
> exists $self->{$key} ? $self->{$key} : $default{$key};
> }
>
> Pretty spiffy.
>
Very spiffy. I love that there's TMTOWTDI. If I was faced with a
similar project I would have tried overriding TIEHASH and fed %default
to it as an argument. Something like this might also do what you want:
package Parameters;
use Tie::Hash;
@ISA = 'Tie::StdHash';
sub TIEHASH {
my ($class, $default) = @_;
$self = { _DEFAULT => $default };
bless $self, $class;
}
sub FETCH {
my ($self, $key) = @_;
exists $self->{$key} ? $self->{$key} : $self->{_DEFAULT}{$key};
}
sub CLEAR { %{$_[0]} = (_DEFAULT => $_[0]->{_DEFAULT}) }
package main;
%default = ( a => "b", c => "d", e => "f", );
tie %param, 'Parameters', \%default;
%param = ( g => "h" );
print $param{"g"}, $param{"a"}; # prints "hb"
I make no judgements on which is "better"--it's just neat to see
different solutions. Then again I may have missed the whole point.
Interesting thread anyway.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Thu, 3 Dec 1998 20:56:47 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: nobody wants a new struct tm (was Re: localtime () - perl's bug ?)
Message-Id: <19981203.205647.2M0.rnr.w164w_-_@locutus.ofB.ORG>
Clive Newall <crn@itga.com.au> writes:
> And a final note: OK. So "struct tm" isn't perfect, and with 20-20
> hindsight every programmer today just *knows* they would have
> designed it better, but it's too late. Rather than argue for change to
> struct tm, people should have been arguing all this time for a better
> (and different) API.
who has been arguing for a non-backwards-compatible change to struct tm?
it's WAY too late for that. we just want the old one deprecated, and
a new one (with it easier to do the right thing than the wrong thing)
to encourage everyone to use.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Mon, 30 Nov 1998 11:21:51 -0500
From: "Erich L. Markert" <erich@orator.usma.edu>
Subject: Re: NT perl and mail
Message-Id: <3662C61F.4CA767CE@orator.usma.edu>
Here's a sub-routine that works on NT 4.0 (for that matter it should work on all systems
that support sockets):
sub send_to{
my $to = shift;
my $body = shift;
my ($replyaddr) = shift;
my $from = $replyaddr;
my $subject = shift;
my $smtp_addr = shift || die "SMTP host undefined\n";
if (!$to) { return -8; }
my ($proto, $port, $smptaddr);
my ($AF_INET) = 2;
my ($SOCK_STREAM) = 1;
$proto = (getprotobyname('tcp'))[2];
$port = 25;
$smtpaddr = ($smtp_addr =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
? pack('C4',$1,$2,$3,$4)
: (gethostbyname($smtp_addr))[4];
if (!defined($smtpaddr)) { return -1; }
if (!socket(S, $AF_INET, $SOCK_STREAM, $proto)) { return -2; }
if (!connect(S, pack('Sna4x8', $AF_INET, $port, $smtpaddr))) { return -3; }
my($oldfh) = select(S); $| = 1; select($oldfh);
$_ = <S>; if (/^[45]/) { close S; return -4; }
print S "helo localhost\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }
print S "mail from: $from\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }
print S "rcpt to: $to\r\n";
$_ = <S>; if (/^[45]/) { close S; return -6; }
print S "data\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }
print S "X-Mailer: USMA Mail.pm \r\n";
print S "Mime-Version: 1.0\r\n";
print S "Content-Type: text/plain; charset=us-ascii\r\n";
print S "To: $to\r\n";
print S "From: $from\r\n";
print S "Reply-to: $replyaddr\r\n" if $replyaddr;
print S "Subject: $subject\r\n\r\n";
print S "$body\r\n";
print S "\r\n.\r\n";
$_ = <S>; if (/^[45]/) { close S; return -7; }
print S "quit\r\n";
$_ = <S>;
close S;
return 1;
}
Jonathan Stowe wrote:
>
> On Fri, 20 Nov 1998 18:03:16 GMT mcnay@my-dejanews.com wrote:
> > I know how to do mail from unix perl scripts. (sendmail)
> >
> > Is there a way, or module to do mail from NT perl scripts. If so, sample
> > please, and what needs to be set up on the machine running the perl.
> >
> > I have a script that is looking at database issues and needs to notify a
> > person if there is problems, since they won't take the time to read the log
> > on the machine.
> >
>
> You might look at perlfaq9 which discusses the use of modules available from
> CPAN for this purpose.
>
> You will probably be interested at looking at DejaNews to review some of the
> occasional turf wars that break out over the various approaches.
>
> /J\
> --
> Jonathan Stowe <jns@btinternet.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
--
__________________________________________________________
Mr. Erich L. Markert erich@orator.usma.edu
USMA Webmaster TEL (914)938-6463
Directorate of Information Management FAX (914)938-7308
United States Military Academy
West Point, NY 10996
"If you put three drops of poison into a 100 percent pure Java,
you get ... Windows. If you put a few drops of Java into Windows,
you still have Windows."
-- Sun Microsystems CEO, Scott McNealy
------------------------------
Date: Fri, 04 Dec 1998 02:42:31 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: NT perl and mail
Message-Id: <r_H92.67$MF3.289@nsw.nnrp.telstra.net>
In article <3662C61F.4CA767CE@orator.usma.edu>,
"Erich L. Markert" <erich@orator.usma.edu> writes:
> Here's a sub-routine that works on NT 4.0 (for that matter it should
> work on all systems that support sockets):
>
> sub send_to{
Oh, yuck!
If you have to talk SMTP directly, use the Net::SMTP module, unless
you are willing to reinvent the wheel, make the same mistakes someone
else made, make a few new mistakes, and manage and maintain all of
this stuff yourself.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd. | password?
NSW, Australia |
------------------------------
Date: Thu, 3 Dec 1998 20:13:17 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: Perl to awk?
Message-Id: <19981203.201317.5Z6.rnr.w164w@locutus.ofB.ORG>
"watsiyem" <watsiyem@vt.edu> writes:
> I am aware of a program that will convert from awk to Perl, but is
> there one available to do the reverse?
perl is vastly more powerful than awk, so any translator would only
be able to convert the most trivial of scripts -- thus I doubt anyone
would bother writing one.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Thu, 3 Dec 1998 22:59:30 -0500
From: "Ernie Oporto" <ernie_oporto@mentorg.com>
Subject: pkzip files with Compress::Zlib??
Message-Id: <747mng$i7m$1@newnews.warren.mentorg.com>
I have a zip format file that I want to unzip. I plan to pull this down on
a regular basis, so it's not something I want to do with another tool. I
want to do this all in Perl.
I can't seem to get the "deflate" to get all the files out of the zip
archive. Would anyone have any sample code to demonstrate this?
-Ernie
--
http://members.spree.com/sip/shokk/
http://www.geocities.com/SiliconValley/Park/9276 - ICQ# 17933910
_____/ ____ / /Ernie "Shokk" Oporto-SysAdmin
_____ ____ / \ __ / __ / Mentor Graphics Corporation
\______/ __ __ \______/ __ \___ __ \___ Ernie_Oporto@MentorG.com
------------------------------
Date: Thu, 3 Dec 1998 20:57:27 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Question about =~
Message-Id: <si67bt7xl4.fsf@cre.canon.co.uk>
David M. Miller <dmiller@fullwave.net> wrote:
> $search = "/look/i";
> my $rc = eval("\$_ =~ $search");
It's better to do
$search = '(?i)look';
/$search/;
>From `perldoc perlre':
(?imsx) One or more embedded pattern-match modifiers.
This is particularly useful for patterns that are
specified in a table somewhere, some of which want
to be case sensitive, and some of which don't.
The case insensitive ones need to include merely
(?i) at the front of the pattern. For example:
--
Gareth Rees
------------------------------
Date: 4 Dec 1998 02:45:05 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Regex question
Message-Id: <slrn76ej5h.82v.sholden@pgrad.cs.usyd.edu.au>
On Thu, 03 Dec 1998 23:39:46 GMT, Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>In article <36671114.1F20A56D@hobbes.clarity.ca>,
> Andy Sharp <asharp@hobbes.clarity.ca> writes:
<snip>
>> while(chomp($n = <FILE>)){ #splits a file on a new line, and removes
>> the \n on the end
>
>You should check for defined here. This code will complain under -w.
>It will attempt to chomp an undefined value.
Plus chomp returns the number of characters it removed so if the last line
of the file has no terminating new line then you will miss it completely.
--
Sam
It has been discovered that C++ provides a remarkable facility for
concealing the trival details of a program--such as where its bugs are.
--David Keppel
------------------------------
Date: Fri, 04 Dec 1998 05:12:27 GMT
From: miko@idocs.com
Subject: regex: anchor or comma
Message-Id: <747qvq$brn$1@nnrp1.dejanews.com>
What is the most efficient way to test if a string is in a comma delimited
string exactly between two commas OR at the beginning OR at the end. I've
played around with this but can't seem to find the magic combination. In my
situation I can assume the fields are not quoted or have embedded commas --
they are just all non-comma string.
Suppose, for example, that I have this comma delimited list:
"fred,barney,betty,wilma"
Now I want to see if that list contains "barney" but not "barn" or "ba". If
there were commas at the start and end of the list I could say /,barney,/ but
I hate having to add those commas (should I?, maybe that's the most efficient
way). Fundamentally, I don't understand how to say "followed by a comma OR
the end of the string".
The way I currently do this is to split the string into hash keys and look for
the key, something like this:
%alreadyReqs=();
@alreadyReqs{split(",",$WebLog::hosts{$request->{host}})}=();
if (! exists $alreadyReqs{$requestKey})
{
yada;
yada;
}
However, that strikes me as somewhat inefficient. Is there a more regex kinda
way to do this?
--
Miko O'Sullivan
Author of The Idocs Guide to HTML
http://www.idocs.com/tags/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 04 Dec 1998 05:49:40 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: regex: anchor or comma
Message-Id: <UJK92.102$MF3.257@nsw.nnrp.telstra.net>
In article <747qvq$brn$1@nnrp1.dejanews.com>,
miko@idocs.com writes:
> Suppose, for example, that I have this comma delimited list:
>
> "fred,barney,betty,wilma"
>
> Now I want to see if that list contains "barney" but not "barn" or
> "ba". If there were commas at the start and end of the list I could
> say /,barney,/ but I hate having to add those commas (should I?,
> maybe that's the most efficient way). Fundamentally, I don't
> understand how to say "followed by a comma OR the end of the
> string".
You could use a character class
/[,"]barney[,"]/
will match a comma _or_ a double quote followed by barney, followed
again by a comma or a double quote.
Alternatively you could check for word boundaries
/\bbarney\b/
which will only match barney if it is surrounded by word boundaries
# perldoc perlre
will tell you more about those.
Of course, if you have possible commas or quotes anywhere else, this
may not give you desirable results. In the second case, if you have
any word boundaries within commas, you also will get odd results.
You didn't actually specify what sort of strings are possible between
your commas, and until we know, we won't be able to provide answers
that take care of any oddities..
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd. | make a better idiot.
NSW, Australia |
------------------------------
Date: Thu, 3 Dec 1998 20:48:19 -0800
From: "Darren" <darrensweeney@eswap.co.uk>
Subject: SDBM search script
Message-Id: <747pjn$bvj@sjx-ixn4.ix.netcom.com>
Hi
I am trying to locate a script which will allow me to search and then
display the results when 1 or any number of SDBM databses is searched.
Anybody have any ideas where I might find one??
Thanks a lot ...
Darren
------------------------------
Date: Thu, 3 Dec 1998 23:35:31 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: string to array
Message-Id: <1djhguo.lxxsjt9d3stsN@bos-ip-1-110.ziplink.net>
Erik <eln@cyberhighway.net> wrote:
> // suggests a pattern, not necessarily a regex.
The difference being...?
All patterns in Perl are expressed as regular expressions. Refer to the
Programming Perl glossary, "pattern matching" and "regular expression".
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Thu, 3 Dec 1998 20:52:35 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: the Unix epoch is not the beginning of time (was Re: localtime () - perl's bug ?)
Message-Id: <19981203.205235.8a5.rnr.w164w_-_@locutus.ofB.ORG>
lr@hpl.hp.com (Larry Rosler) writes:
> I don't understand why someone changed the title of this thread
yes, you've demonstrated that you don't understand. you seem rather
comfortable in that lack of understanding, though.
> The function presented is accurate (and, IMO, trivial).
yes. it _was_ trivial.
didn't that strike you as odd? that there was a trivial solution to
this problem that many people are concerned about?
did you think that perhaps you weren't solving the right problem?
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Thu, 3 Dec 1998 18:51:09 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: usage of $_ within nested loops
Message-Id: <sid86183fm.fsf@cre.canon.co.uk>
Thomas Janke wrote:
> How will Perl handle the usage of "$_" within nested loops?
Larry Rosler wrote:
> $_ is a 'global' variable. Its value is not affected by nested blocks,
> or other scopes such as subroutine bodies, for example.
However, the various looping constructs that implicitly assign to $_:
`while', `for', `foreach', `until', `grep', 'map' automatically localize
$_:
This program:
$_ = 0;
foreach (1) {
print "in outer loop: \$_ = $_\n";
foreach (2) {
print "in inner loop: \$_ = $_\n";
}
print "in outer loop: \$_ = $_\n";
}
print "outside grep: \$_ = $_\n";
grep { print "inside grep: \$_ = $_\n" } 3;
print "outside grep: \$_ = $_\n";
print "outside map: \$_ = $_\n";
grep { print "inside map: \$_ = $_\n" } 4;
print "outside map: \$_ = $_\n";
produces the following output (using Perl version 5.005_02):
in outer loop: $_ = 1
in inner loop: $_ = 2
in outer loop: $_ = 1
outside grep: $_ = 0
inside grep: $_ = 3
outside grep: $_ = 0
outside map: $_ = 0
inside map: $_ = 4
outside map: $_ = 0
--
Gareth Rees
------------------------------
Date: 03 Dec 1998 21:48:32 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: usage of $_ within nested loops
Message-Id: <x7ww48wrjz.fsf@sysarch.com>
>>>>> "GR" == Gareth Rees <garethr@cre.canon.co.uk> writes:
GR> print "outside grep: \$_ = $_\n";
GR> grep { print "inside grep: \$_ = $_\n" } 3;
GR> print "outside grep: \$_ = $_\n";
GR> print "outside map: \$_ = $_\n";
GR> grep { print "inside map: \$_ = $_\n" } 4;
s/grep/map/ ;
GR> print "outside map: \$_ = $_\n";
be careful of that cut and paste coding! otherwise a good example.
:-)
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Thu, 3 Dec 1998 23:35:32 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: variable inside variable
Message-Id: <1djhh9r.157dxxr6i7vvdN@bos-ip-1-110.ziplink.net>
Tk Soh <r28629@email.sps.mot.com> wrote:
> > Perl FAQ, part 4:
> >
> > "How can I expand variables in text strings?"
>
> the faq suggested using s///, but I find using eval is more
> straight-forward (not sure about effeciency, yet). Anything hiding from
> me ?
How about this?
template file:
Expand this variable: $foo
And this one: ${\(`rm -rf *`)}
Gotcha!
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 04 Dec 1998 03:30:33 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: wantarray() question.
Message-Id: <36675910.2E19E097@shaw.wave.ca>
[posted & mailed]
"Mike D." wrote:
>
> I have a function called employees, I would like it to return the
> number of employees if called in scalar context or the all the
> employees if called in list context.
[
snipped code that's basically:
sub { return @array }
]
> So here is the question, would it be more efficient to rewrite the
> fuction like:
[
snipped code that's basically:
sub { wantarray ? @array : (scalar @array }
]
I don't see how the second could be any more efficient than the first,
plus it's uglier. If you want to compare them for speed you could use
the Benchmark module but that would probably be pointless.
The main thing to be aware of here is that an array in list context
returns the list of all its elements. An array in scalar context
returns the number of elements.
This is exactly the behaviour you want so you might as well take
advantage of this well designed feature of Perl. Just return the array
and let the context take care of itself.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Thu, 3 Dec 1998 23:35:33 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Why is "... @foo ..." occasionally a syntax error?
Message-Id: <1djhi7n.ebog5vd2s5nnN@bos-ip-1-110.ziplink.net>
John Chambers <jc@eddie.mit.edu> wrote:
> > So, the way to declare an array is:
> >
> > my @foo;
>
> But this would shoot down the whole body of code that I started this
> with. The variable in question must be global; adding a my declaration
> would hide it from the routine that's trying to get at the data left
> there by another routine. There seems to be no "global @foo" sort
> of statement in perl. (Or did I miss it?)
You missed it.
use vars qw(@foo $bar %baz);
But I can't help thinking you're being purposely obtuse, because this is
explicitly mentioned in perldiag, under the warning which you just said
you were getting:
Name "%s::%s" used only once: possible typo
(W) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention
it again somehow to suppress the message. The C<use vars> pragma is
provided for just this purpose.
No wonder you didn't know about 'use vars', if you didn't bother reading
the documentation.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed 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 V8 Issue 4356
**************************************