[10545] in Perl-Users-Digest
Perl-Users Digest, Issue: 4137 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 3 00:08:18 1998
Date: Mon, 2 Nov 98 21:00:16 -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 Mon, 2 Nov 1998 Volume: 8 Number: 4137
Today's topics:
Re: ActiveX and Perl <ismkoehlerism@nmism-us.campus.mci.net>
custom log file parsing <hareed@bellsouth.net>
Re: FTP from Win32 helphand@pacbell.net
Installing large quantities of modules mlehmann@prismnet.com
Loading Math::Random Module <tpham@ee.gatech.edu>
Re: New posters to comp.lang.perl.misc (Tad McClellan)
New to Perl Question .. Get system info from another ma <sorry@nospam.com>
Re: Not to start a language war but.. <rra@stanford.edu>
Re: Not to start a language war but.. (William Tanksley)
Re: Not to start a language war but.. <tchrist@mox.perl.com>
Re: Not to start a language war but.. <rra@stanford.edu>
Re: Not to start a language war but.. (William Tanksley)
Re: Not to start a language war but.. <dalke@bioreason.com>
Outputting HTML/JAVA SCRIPT though Server Side Includes (Dico Reyers)
Re: Perl & Y2K - booby trap code (Snowhare)
Re: PERL script for auto-mailing a binary file helphand@pacbell.net
Re: Shell built-in commands in a perl script? <kprice@cardinal.co.nz>
Re: Very Large DBM file: Finding Number of keys (Larry Wall)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 2 Nov 1998 20:26:46 -0700
From: "Rick K" <ismkoehlerism@nmism-us.campus.mci.net>
Subject: Re: ActiveX and Perl
Message-Id: <71lt4k$f01$1@news.campus.mci.net>
Roger Kenneth Trussell wrote:
>[snip]
>Does anyone know whether there exist a version of Perl for Windows
>95/95/NT that can access ActiveX objects [snip]
Check out O'Reilly's Win32 Perl Resource Kit, which contains PerlCOM
and PerlCtrl. These tools are discussed in the latest issue of *The Perl
Journal* (Issue #11, Fall 1998), in an article by Brian Jepson.
You can build ActiveX controls in Perl using PerlCtrl.
PerlCOM is an ActiveX component that "exposes a Perl interpreter".
I recommend digi-hoofing it to www.ActiveState.com and
www.perl.oreilly.com as well as subscribing to TPJ. HTH.
------------------------------
Date: Tue, 03 Nov 1998 04:05:07 GMT
From: "Harold Reed" <hareed@bellsouth.net>
Subject: custom log file parsing
Message-Id: <Thv%1.111$kG1.408983@news4.atl.bellsouth.net>
A question on parsing a custom log file.
The file is in the format as such:
[[PRE unique_id]]
field1: data1
field2: data2
field3: data3
fieldn: datan
---------
other
ancillary
data
[[/PRE]]
with a corresponding [[POST]] section.
I need to match up the PRE and POST sections and check values from each.
>From the Perl Cookbook, I gleaned:
print OUTPUT if /\[\[PRE/ .. /\[\[\/PRE/;
but can't quite seem to get the things inbetween into a usable form. I tried
reading in into a variable
$variable = /\[\[PRE/ .. /\[\[\/PRE/;
and then splitting the variable into array values, but no luck.
Any suggestions?
------------------------------
Date: Tue, 03 Nov 1998 03:49:08 GMT
From: helphand@pacbell.net
Subject: Re: FTP from Win32
Message-Id: <363e7a64.118320973@news.pacbell.net>
On Tue, 03 Nov 1998 00:25:39 GMT,
spamtrap.david.whitmarsh@dial.pipex.com (David Whitmarsh) wrote:
>
>I regulary use Net::FTP on a laptop that is sometimes connected to a
>LAN and also uses a dialout network connection. It works with both
>whether one or both are active at any time. I.P address for the
>dialout is dynamic, but fixed for the LAN, the LAN uses one of the
>reserved non-routed address ranges.
>
>I don't use DNS on my LAN at the moment, but I have had in the past.
>
>When using DNS on two networks, win95 does seem to get confused and
>tries to do lookups on the the network you aren't connected to, and
>only tries the other after a long time-out interval. Try changing the
>order of DNS servers in your tcp/ip config. That may not be it, but
>I'll bet it is DNS related in some way.
>
I agree. It's either DNS or some other obscure configuration problem
on the Win95 side. But, just in case it's another clue, my setup that
causes the problem only has one DNS server configured... the one
associated with the dialout that has a fixed IP number associated with
it... so I can't switch the order. The LAN's non-routed with no DNS
server on it.
I've convinced myself that there's nothing wrong with Net::FTP,
whatever the problem is, it's a Win95 one ;)
Thanks for your input. It bugs me so much I keep following any
thread that mentions FTP in hopes that someone eventually figures it
out <g>.
Scott
--------
Delta Performance Group, "Achieving the Competitive Edge"
http://www.deltagrp.com/
------------------------------
Date: Tue, 03 Nov 1998 04:36:51 GMT
From: mlehmann@prismnet.com
Subject: Installing large quantities of modules
Message-Id: <71m194$rb7$1@nnrp1.dejanews.com>
I continue to manage and maintain hundreds of perl libraries (.pl), modules
(.pm), and scripts (.pl again).
I have placed all of the modules in a single flat directory that I'll call
/usr/local/lib/perl5/imtired. That works ok and lends itself to nice source
code control, but is not in a format that is CPAN friendly. While I doubt
this custom code and the custom libraries will ever make their way to CPAN, I
would like to do things in a CPAN way.
So I am using techniques suggested by Joseph Hall (and probably Randal
Schwartz) in the book "Effectvie Perl Programming" that describe how to have
the h2xs command build module trees for me, without the C stub code.
h2xs -A -X -n To_Much_Jolt
This builds a directory tree for me, some boilerplate files, and a Makefile.PL
file for me. I can easily install this one package with the commands:
perl Makefile.PL
make install
But I will have dozens of these packages and I need to be able to
conveniently tar them up into an install package, then move that code to
multiple remote computers, untar the files on the remote machine, and then
install all of the packages. How is this done. I've looked through the
MakeMaker pod file and move of the O'Reilly books on perl, but I don't find
an answer to this. I'll invent a way, but I don't want to re-invent the
wheel. Suggestions and pointers to documented solutions would greatly help.
Thanks.
--
Give someone a Perl script and they can hack for a night, teach them Perl, and
they can hack for a lifetime.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 02 Nov 1998 23:14:05 -0500
From: Tien Pham <tpham@ee.gatech.edu>
To: tpham@ee.gatech.edu
Subject: Loading Math::Random Module
Message-Id: <363E830D.F3D5A3FF@ee.gatech.edu>
Hi everyone,
Recently I tried to load the Math::Random module
(which I obtained from CPAN) but got no success.
I got the following error message:
-----------------
Can't locate Math/Random.pm in @INC
(@INC contains: /usr/local/lib/perl5.004/lib/sun4-solaris/5.00404
/usr/local/lib/perl5.004/lib
/usr/local/lib/perl5.004/lib/site_perl/sun4-solaris
/usr/local/lib/perl5.004/lib/site_perl .) at example.pl line 4.
BEGIN failed--compilation aborted at example.pl line 4.
-------------------
I tried to modify the code to include the path to Math::Random:
#!/usr/local/bin/perl -w -I/home/tpham/tmp/MathRandom
but got no success.
I also tried to modify @INC explicitly
---------------------
unshift (@INC, "/a/elijah/export1/home/tpham/tmp/Math");
for $oho (0..$#INC) {
print STDOUT "$INC[$oho]\n";
}
use Math::Random qw(:all);
----------------------
but also got no success. (Same error message).
When I obtained the tar file from CPAN, after gunziping & untar, I got
a dir called MathRandom. Since the error complains not be able to find
the Math/Random.pm, I change MathRandom to Math. This still does not work.
Could anyone give me some lights?
I appreciate for your help,
tien pham
tpham@ee.gatech.edu
--
Plan:
To live
To enjoy
To appreciate
every opportunity and every minute here, in America!
--------------------------------------
------------------------------
Date: Mon, 2 Nov 1998 22:03:35 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: New posters to comp.lang.perl.misc
Message-Id: <navl17.af5.ln@flash.net>
Dan O'Connor (dan@ferrarinet.reno.nv.us) wrote:
: You people
Since you phrase it that way, it becomes apparent that
you are not one of us.
: here spend half your time telling people that their posts aren't
: related to Perl.
Uh, maybe because of the high percentage of posts to this
Perl newsgroup that are not related to Perl?
Don't shoot the messenger...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 2 Nov 1998 21:57:11 -0500
From: "CLee" <sorry@nospam.com>
Subject: New to Perl Question .. Get system info from another machine ie.. diskspace/# WINS addresses
Message-Id: <71lr5q$5fv$1@excalibur.flash.net>
I am very new to Perl and was wondering how possible and what help I could
get to do the following.
1. Get drive free space from a server across a TCP/IP connection
2. Get available WINS addresses from the WINS Server
3. Capture Errors from the event log from the server across the network.
I forgot to mention this is on a NT Network using Activestates interpreter.
I also have started to play with the module Adminmisc and it seems to
address some of my issues.
Thanks in advance.
Leo
NT Admin, MCSE
leo.mcse@softhome.net
------------------------------
Date: 02 Nov 1998 18:52:04 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Not to start a language war but..
Message-Id: <yld875h4iz.fsf@windlord.stanford.edu>
In comp.lang.perl.misc, Greg Ewing <greg@cosc.canterbury.ac.nz> writes:
> Russ Allbery wrote:
>> Right. That's exactly my point. If I want conceptual error
>> information propagated along with my error (and in general I definitely
>> *do* want that), I'd have to throw my own exception. That, at least to
>> me, significantly reduces the usefulness of Python's automatic
>> exception throwing, since if I want production-quality error reporting
>> I can't use that anyway.
> Yes, you can. All you need to do is catch the exception at those places
> where conceptual information is available and pass on a new, value-added
> exception. E.g.:
[...]
To me, this qualifies as "not using the automatic exception throwing"
because I'm going to more work to provide specific error messages, the
same as I would do in Perl with an explicit call to die().
My argument is basically that I nearly always want to put information into
error messages that the language has no way of deriving programmatically,
since it's conceptual information about what the program was attempting to
do at the time. I'm therefore stuck either throwing my own exceptions or
doctoring the exceptions that are thrown, and therefore the real practical
difference between manually throwing exceptions and having exceptions
thrown automatically is fairly minimal.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 03 Nov 1998 03:16:52 GMT
From: wtanksle@cx930311-b.ocnsd1.sdca.home.com (William Tanksley)
Subject: Re: Not to start a language war but..
Message-Id: <slrn73std3.b16.wtanksle@cx930311-b.ocnsd1.sdca.home.com>
In article <363DD845.66165EAB@min.net>, John Porter wrote:
>William Tanksley wrote:
>> Unfortunately, Perl code is complex as well.
>> ML or Prolog are complex languages with simple code. That's a feature. Perl
>> is a complex language with complex code, and that's because of missing
>> features.
>I'm sorry to be so blunt, but -- that's a lie. A raw, bare lie.
>Whether you are intentionally prevaricating, or are simply uninformed, I
>don't know.
A 'lie' is always intentional. If I'm wrong, please tell me so. I consider
myself told. ;-). In the future please consider the distinction -- any
idiot can be wrong (I do it all the time); only a dishonest person would lie
(and I'd have to be both dishonest and an idiot to lie about Perl _here_).
Argue the issues, not the personalities.
>But apart from the fact that such a statement is a gross generalization, to
>the point of worthlessness, *much* perl code is not complex. The language
>was designed to be a high-level language, wrapping much usefully complex
>functionality in the built-in operators (and "engines", like regex).
>Sure it's possible to write complex code; but it's not the norm.
>I'm just trying to point out that just because some code is inscrutable
>doens't mean that code is *complex*.
Perhaps my statement was too complex. ;-). I take the blame; I wasn't at
all clear. What I _meant_ is that it's not possible to avoid many of the
effects of Perl's complexity in writing code.
Let me compare.
Prolog supports backtracking, an extremely complicated operation, with
syntax that hardly looks like more than an assignment. Nice, when you need
it.
Perl supports line-based file reading, a complicated operation, with
(simple) syntax that looks like a while loop. Handy.
Perl also supports multiple syntactic ways of writing the same conditional
(certainly complicated to parse). Very handy.
Perl supports variable access, a simple operation, with syntax that looks
like an array reshape in J.
Perl supports passing scalars to a function... Sort of. Arrays? You're on
your own, try implementing your own function passing protocol.
In general, Perl makes many complicated things simple. Applause. Perl then
goes on to make many simple things complicated. Boo, hiss.
>Now please don't take this as a knock on Python or any other language.
>I'm drawing no comparisons here.
Perhaps Python needs some knocking too, but it would expand the message a
little too much :-). At any rate, I'm here (in comp.lang.perl) to learn
Perl, not Python, even though so far I see almost no reason to like Perl.
Aside from the prior art, of course, but then that never made me like
Fortran no matter HOW much better than assembly language it might be.
>> Python is n-bit clean, where n is the size of your data structures. Not
>> everything is an array of char, no matter what ANSI (the C standard) says.
>Sure, if by "data structures" you mean the native word size on your machine.
Eh? No, any data structure you want. Classes, tuples, hashes, you name it.
Even functions, assuming that they're written in Python (if you write them
in native code Python will have some trouble handling them).
>"8-bit clean" refers to the (near-universal) adoption of the octet as the
>basic unit of addressable data at the machine level. Being "8-bit clean"
>means that no values in the range of possible values of an octet (0-255)
>are reserved for special purposes (e.g. sentinels) by the language.
Splendid. What's even better, Perl is being prepared for 16-bit (Unicode)
and variable-width (UTF-8) cleanness.
>I'm sure Python is 8-bit clean. But let's call it that, because that's what
>it is.
Your point was, I believe, that Perl is good at handling data because Perl
can handle arbitrary streams of bytes very well. My point is that Perl is
not very good at handling data because it can't handle arbitrary structures
very well.
Don't get me wrong: it handles them, all you have to do is work with it.
But its support is concentrated entirely on handling streams of bytes.
>> > public StringBuffer append (boolean bool) { _extractStringBuffer().append (bool); type = STRING; return string; }
>> [plus a mess of almost identical overloadings of the same function,
>> differing only in type]
>> Second, the main reason you put all those functions flat next to each other
>> is that they're all the same text, only different data types. Er -- that's
>> not needed in Python, even though it is in Perl. All data types are first
>> class, including hashes, arrays, and scalars.
>It's not needed in Perl either, although for slightly different reason.
Well, I'd say it's pretty much the same reason. Both of them have runtime
types, even if Perl does make textual distinctions between a few of its
types.
It's kind of silly to bring up a Java example here, though :-).
>The RTTI of the arguments is available for inspection by the called function.
>Any user-defined function can be inherently polymorphic, if desired.
>Of course, it comes down to some kind of switch on the argument types,
>which could look a little ungainly.
That's a price you pay almost anywhere -- even if the language allows you to
access the variables themselves the same (as does Python), their contents
will still be reached differently. Perl's as good as any here :-), and
better than Java in specific. But is that the kind of praise you want to
hear?
>John Porter
-Billy
------------------------------
Date: 3 Nov 1998 04:05:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Not to start a language war but..
Message-Id: <71lvf0$6v3$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
wtanksle@cx930311-b.ocnsd1.sdca.home.com (William Tanksley) writes:
:Perl supports passing scalars to a function... Sort of. Arrays? You're on
:your own, try implementing your own function passing protocol.
I beg your pardon? Who told you this very silly thing? It's
so far from accurate that I cannot believe it's in an intentional lie.
Therefore, I can only surmise that you don't understand pass-by-reference
semantics. Please consult perlsub.
:My point is that Perl is
:not very good at handling data because it can't handle arbitrary structures
:very well.
:Don't get me wrong: it handles them, all you have to do is work with it.
I dunno. I write things like
$tv_show{"Flintstones"}{"kids"}[0]{"age"}++
Or even the classic linked-list traversal:
for ($node = $head; $node; $node = $node->{LINK}) {
printf "I am %d.\n", $node->{VALUE};
}
without having to "work with it" all that much. What's your gripe?
--tom
--
Never eat more than you can lift.
--Miss Piggy
------------------------------
Date: 02 Nov 1998 20:20:23 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Not to start a language war but..
Message-Id: <ylhfwhflvc.fsf@windlord.stanford.edu>
William Tanksley <wtanksle@cx930311-b.ocnsd1.sdca.home.com> writes:
> Perl supports variable access, a simple operation, with syntax that
> looks like an array reshape in J.
I've honestly never understood this complaint, or at least it seems too
broadly applied. Perl's way of accessing complex data structures is
undeniably ugly; I don't know of anyone who honestly *likes* notation like
@{$$self{array}}. I put up with it because it's consistent and not *that*
hard to remember, but it would be nice to have a simpler notation.
But regular variable access looks just like C; there's just this weird
naming requirement on variables that's a little like Hungarian notation.
$foo, @bar, %baz, $bar[2], and $baz{foo} seem very natural to me, and I
don't see what's complicated about that syntax. "$foo" is the name of the
variable; the variable isn't "foo" and the $ something else. Maybe the
confusion comes from people not thinking about it that way? If you do
think of it that way, it then becomes obvious that "$foo" and "@foo" are
two different variables.
> Perl supports passing scalars to a function... Sort of. Arrays?
> You're on your own, try implementing your own function passing protocol.
Er? I pass arrays to functions all the time, and choose between pass by
value and pass by reference just like I would in C or Pascal or most any
other language I'm familiar with. What's tricky about this in Perl?
Is it the behavior of Perl when you're passing *two* arrays to a function
the part that you don't like? If that's the case, then yes, it's a little
annoying. But if you pass by reference instead of value (which does have
a notation hit on dereferencing, I'll admit), it's not too bad.
> In general, Perl makes many complicated things simple. Applause. Perl
> then goes on to make many simple things complicated. Boo, hiss.
I think this same thing can be said of all languages. :)
> Perhaps Python needs some knocking too, but it would expand the message
> a little too much :-). At any rate, I'm here (in comp.lang.perl) to
> learn Perl, not Python, even though so far I see almost no reason to
> like Perl.
Things to like about Perl:
* It's succinct. You don't have to write 40 lines of code to express a
simple concept. This saves you time and also saves you *some* bugs, as
the number of syntax and similar "minor" errors per line of code is
fairly constant across all languages (there's been quite a bit of
theoretical work done on that point).
* The regular expression support is amazing. There's basically no text
mangling I can think of that Perl can't do with at least reasonable
efficiency compared to other languages.
* Both network programming *and* text mangling are easy to do, in the
same language. This is one of the big gripes that I have with other
scripting languages (I haven't evaluated Python in particular on this
score); networking is amazingly hard. In languages where networking is
easier (C), text mangling is hard. I do both in Perl fairly easily.
The cleaner syntax is definitely something to like about Python. Like I
said, I'm not fond of Perl's syntax for complex data structures at all.
But I *do* like Perl's DWIM support, and would rather write in a language
that has it than in one that doesn't.
The other important point about Perl for me is that writing in Perl is
fun. The language has lots of little nooks and crannies that one can
explore to write succinct and beautiful expressions of an algorithm.
That's important to me; I like to have fun when writing code. That's a
very personal reason to like Perl, and your mileage may vary.
> Aside from the prior art, of course, but then that never made me like
> Fortran no matter HOW much better than assembly language it might be.
The prior art and the nature of the community are a big ones for me. The
number of modules available for Perl (and the number of problems that are
already solved for me, meaning that I don't have to do anything at all) is
an important feature.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 03 Nov 1998 04:29:51 GMT
From: wtanksle@cx930311-b.ocnsd1.sdca.home.com (William Tanksley)
Subject: Re: Not to start a language war but..
Message-Id: <slrn73t1lt.b16.wtanksle@cx930311-b.ocnsd1.sdca.home.com>
In article <F1ssoC.Lzs@world.std.com>, Anita M Wilcox wrote:
>>>: * its cleaner and simpler.
>>> Perl is complex, it's a feature.
>>It sure is. Unfortunately, Perl code is complex as well.
>Can we say "job security"?
Grin. I like that.
>Seriously, whether you prefer one
>language over another, it is irrelevant as far as your career
>goes if no one will hire you to work with it. I'm a consultant
>and have to have a fairly broad repertoire of skills, and, as
>such, have to try to cram in learning as much as possible. In
>terms of the Python/Perl debate, Perl wins hands-down. Scan
You're totally right; in fact, that's why I'm here, because some
pointy-haired individuals decided that the programmer doesn't need to decide
what language they're going to use. I'm exaggerating my own annoyance,
actually; when they suggested this I opposed it mildly, but agreed because I
figured that all those Perlers couldn't be THAT wrong, and I was obviously
missing something about the language.
I've picked up a lot more, and I see a lot of the stuff that makes Perlers
happy. I like it too. I just still don't see why I should like the
language. Really, I do want to like the language -- my arguments
notwithstanding.
>Often, you get a semi-computer-literate VP who has seen demos
>of nifty little Java apps, so they think that's the "wave of
>the future", when something like Perl would be a more efficient
>solution. Once these guys get fixated on their tool of choice,
>every problem is a nail and that's their hammer. It's not
>the way I'd like it to work, but "them that has the gold makes
>the rules" :-)
Fortunately, not everything works this way. I'm salaried, so in many cases
I get my own choices.
I'm trying to find a way to be enthusiastic about programming in Perl -- you
guys make it sound like so much fun. And I'm not disappointed yet, just a
little puzzled. "Because I have to" is a great reason to choose a
programming language; it doesn't make much sense as a reason to argue about
one.
>Anita
-Billy
------------------------------
Date: Mon, 02 Nov 1998 11:45:06 -0700
From: Andrew Dalke <dalke@bioreason.com>
Subject: Re: Not to start a language war but..
Message-Id: <363DFDB2.FD0E4385@bioreason.com>
(Figured that if I broke my vow not to enter this thread, I might
as well continue.)
The story thus far ....
David Formosa <dformosa@zeta.org.au> mentioned a perl snippet he uses:
> if (not open ARTICAL,"<$filename") {
> warn "Can't open artical file $filename because $!";
> next;
> }
Jason Orendorff <jorendorff@ixl.com> gave a solution in Python that
used sys.stderr as a way to implement warn.
Sam Holden <sholden@pgrad.cs.usyd.edu.au>, who is perhaps more
knowledgeable about the details of Perl semantics than your typical
Python developer said:
> Except of course that warn does not have to output to stderr...
>
> $SIG{__WARN__} can do whatever it likes with it (useful in things such
> as CGI (though you should just use CGI.pm)).
> [...]
> So the equivelant python is...?
(Even though we were talking about handling exceptions from "open",
but I can deal with changes of subject.)
This author, being of the masochistic sort, decided to implement the
request by writing a Perl semantic emulation module. (MMmmmm. Beat
me, hurt me, make me write bad checks!) Here's my solution (assuming
for testing the code that surrounds it):
= = = = =
import Perl
def check_files(files):
openable = []
for filename in files:
ARTICAL = Perl.open(filename)
if not ARTICAL:
Perl.warn("Can't open artical file %s because %s" %
(filename, Perl.ERRNO))
continue
openable.append(filename)
return openable
# And some test code
files = ("/nothing", "/etc/passwd", "/var/spool/cron/crontabs/root")
print " ---- First version ----"
print check_files(files)
print " ---- Without warnings ----"
Perl.SIG["__WARN__"] = None
print check_files(files)
= = = = = =
Running the code (some line wraps introduced for Usenet clarity)
bioreason8> python emu_perl.py
---- First version ----
Can't open artical file /nothing because No such file or directory at
test_perl.pl (check_files) line 7.
Can't open artical file /var/spool/cron/crontabs/root because
Permission denied at test_perl.pl (check_files) line 7.
['/etc/passwd']
---- Without warnings ----
['/etc/passwd']
= = = = = =
I trust that is sufficent emulation? :)
Oh, and here's my Perl emulation module for the truly bored.
Feel free to do whatever you want with it, but don't call it
George, since it prefers "King of the Jungle."
= = = = = =
#
# Let's emulate some perl-like calls
#
import sys, os
# I have no idea if this does exactly the correct semantics
# as perl. It's enough to emulate the example given plus what I
# remember when I was a perl junkie.
def print_warn(message):
# Lemme see, if it ends in a newline, just dump to stderr, right?
if message[-1] == "\n":
sys.stderr.write(message)
return
# Otherwise, get the filename and line number of the error.
# For fun, let's get the function name too :)
# I don't know the "real" way to get the caller's line number
# but this works.
try:
1/0
except ZeroDivisionError:
x = sys.exc_info()[2]
# From the traceback, get the caller's frame. This is
# two frames up (since we're called from "warn")
frame = x.tb_frame.f_back.f_back
# get line number, filename and function name
line = frame.f_lineno
filename = frame.f_code.co_filename
fctnname = frame.f_code.co_name
sys.stderr.write(message + " at %s (%s) line %d.\n" % \
(filename, fctnname, line))
def warn(message):
# defer action to the current value in SIG
# This lets someone else override it. Not very thread-safe,
# if you ask me, but I guess you aren't :)
action = SIG[__WARN__]
if action:
action(message)
# No, I'm not going to emulate "<", "<<", etc. since then I'll have
# to so all that nasty stuf so "< file with spaces \0" is translated
# correctly.
# This just handles the exception semantics
# We still want access to the real open, so rename it
if 'python_open' not in dir(): # be nice to reloads
python_open = open
def open(filename):
global ERRNO
try:
f = python_open(filename)
ERRNO = None # It worked. Imagine that...
return f
except IOError, err:
# Keep error info so caller can admire at it
ERRNO = ErrNo(err.errno, err.strerror)
# if it fails, returns nothing
# Do the funky $! semantics (can return either integer or
# string values, given context)
class ErrNo:
def __init__(self, errno, errmsg = None):
self.errno = errno
if errmsg is None:
# figure it out for ourselves
errmsg = os.strerror(errno)
self.errmsg = errmsg
def __int__(self):
return self.errno
def __str__(self):
return self.errmsg
def __repr__(self):
return "Errno(%d, %s)" % (self.errno, self.errmsg)
# default to no errors
ERRNO = None
# set up the signal handler
SIG = {}
__WARN__ = "__WARN__" # syntatic sugar
# By default, print "warn" signals
SIG[__WARN__] = print_warn
= = = = =
Yeah, there's probable things I'm missing, like getting the right
call parameters to the signal handler. But the point is, if you want
to have specific semantics, wrap it up in a module and use those
functions.
Andrew Dalke
dalke@bioreason.com
------------------------------
Date: Tue, 03 Nov 1998 03:32:16 GMT
From: dico@internetworks.ca (Dico Reyers)
Subject: Outputting HTML/JAVA SCRIPT though Server Side Includes Perl file.
Message-Id: <363e791a.41150253@news.mtt.net>
Hello there...
Is it possible to have a Server Side Included call that runs a perl
script that output some stuff to the web page including java script?
Or does the java script have to be part of the original HTML file?
Also, how does one print out a whole bunch of HTML through a perl
script. Rather then typing...
print "this that and the other thing\n";
print "and then some more....\n";
print "and yet some more...\n";
(you get the idea).
Is there something where I can just type some Perl stuff and then cut
and paste in a half page of HTML/Javascript and then end the pasting?
thanks in advance,
-Dico
dico@peionline.com
------------------------------
Date: 3 Nov 1998 03:51:40 GMT
From: snowhare@devilbunnies.org (Snowhare)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <71lukc$qgs$1@nnrp3.snfc21.pbi.net>
Nothing above this line is part of the signed message.
In article <717l83$qv9$1@srv38s4u.cas.org>, <lvirden@cas.org> wrote:
>
>According to Matt Knecht <hex@voicenet.com>:
>:Wheny ou say we're not going to get it all finished, and mistakes will
>:be made, who are you refering to? Does anybody reading this group have
>:the misfortune to work in a shop where this is a concern?
>
>Monday I was in a meeting. A sysadmin mentioned to me that he was setting
>up the latest version of Netscape Certificate server for Solaris 2.6.
>He specified a date two years in the future for the certificate to expire.
>The server reported back that the certificate would expire 10/26/101 ...
Here is a *live* example of someone (not me) being bitten by year - 1900
in Perl that I just found while cleaning out my old mailboxes:
# Avoid an embarassing year 2000 glitch in three years...
# If we're selling the product after the year 2099 I won't care...
if ($eyear < 97) {
$eyear = "20$eyear";
}
else {
$eyear = "19$eyear";
}
The comment is in the original code. Yeppers....
Benjamin Franz
Version: 2.6.2
iQCVAwUBNj5+HOjpikN3V52xAQH2jQP+ORvG1+BaWJ/1xCnZyKbKHfdZgzstNAlL
33u4CxgPFWC8nTYa1tLDcca1fOophmyEa90nxryaFLSzy/gc2gnZTMtFbrM1cU3Z
Lbxve96s0kgMbGV1RmoYcu+znryVjMYlNJyKzHi2fk+2czfOBmQMl3GrPnLDOIZW
JCOo/7BCYjI=
=dJiF
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 03 Nov 1998 04:31:11 GMT
From: helphand@pacbell.net
Subject: Re: PERL script for auto-mailing a binary file
Message-Id: <363f85ad.121209966@news.pacbell.net>
On Mon, 02 Nov 1998 16:51:37 GMT, "E. Preble" <preble@ipass.net>
wrote:
>I've set up an auto-responder for sending out a file after a request by a
>user. Text files work fine, but binaries (*.exe files) come through as
>garbled ascii rather than as binary attachments.
>
>I'd rather not uuencode.
>
>I'm currently sending everything using sendmail. I've tried many scripts,
>but none seem to work. Can Perl do this?
>
Yes. Use MIME::Base64 (avail from CPAN) to encode the binary file.
Works great, but you do need to get the MIME headers right. If you
need help, I can post example code, but it uses Net::SMTP not sendmail
(sorry, I'm not up to speed with sendmail).
HTH,
Scott
--------
Delta Performance Group, "Achieving the Competitive Edge"
http://www.deltagrp.com/
------------------------------
Date: Tue, 03 Nov 1998 16:41:40 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Shell built-in commands in a perl script?
Message-Id: <363E7B74.81086E1C@cardinal.co.nz>
Steve Goldstein wrote:
>
> I want to use the shell built-in "source" command in my perl script.
> How do I do it?
>
> If I use
> system("source <filename>") or `source <filename>`
> in my script, I get the error message:
> Can't exec "source": No such file or directory...
Assuming you are on a unix system ...
system("sh -c \"source <filename>\"");
might do what you want
------------------------------
Date: 2 Nov 1998 19:30:40 -0800
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <71ltd0$hof@kiev.wall.org>
In article <71ctr9$a12$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>That's what I thought too, but we're mistaken. Try
>
> perl -Dx -e '$s = keys %h'
> perl -Dx -e '$s = scalar keys %h'
>
>and you'll see that the second one contains a call to the pp_scalar opcode.
>However, if you look at the code (around line 117 of pp.c) you'll see
>that it's probably the fastest opcode there is.
>
>It seems as though an sassaign(scalar(...)) is a good candiate for the
>peephole optimizer.
Good idea. In fact, hang on a sec...
Okay, I've fixed it on your machine. Run your command again and you'll
see the peephole optimizer is now bypassing the opcode.
:-)
Larry
------------------------------
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 4137
**************************************