[8596] in Perl-Users-Digest
Perl-Users Digest, Issue: 2213 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 31 01:07:43 1998
Date: Mon, 30 Mar 98 22:00:28 -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, 30 Mar 1998 Volume: 8 Number: 2213
Today's topics:
Re: an extension question (Tye McQueen)
Re: Date manipulations? (Tom Mornini)
Re: debugging Perl <rjk@coos.dartmouth.edu>
Re: File IO Question: opening for appending without flo (M.J.T. Guy)
Re: file trees (Earl Hood)
Re: free disk space <smubit1@gl.umbc.edu>
Hash Of Hashes vs. Hash With Split (Troy Denkinger)
Re: help needed with grep type function for perl script (M.J.T. Guy)
Re: help needed with grep type function for perl script <lr@hpl.hp.com>
Re: help needed with grep type function for perl script <lr@hpl.hp.com>
Re: Is there a "Newsgroup" for Newbies to Perl? <sneaker@mediaone.net>
Re: Kill Signals going to forked System command not Per (M.J.T. Guy)
Re: math: random numbers.. well, sorta-kinda.. <merlyn@stonehenge.com>
Re: MSEXCHANGE / OUTLOOK <rjk@coos.dartmouth.edu>
Re: Need help with "shared memory" module IPC::Shareabl <zenin@archive.rhps.org>
Re: proposal: while $line (<FILE>) <scribble@pobox.com>
Re: Public Key Encryption (non pgp) <jhoglund@mirage.skypoint.net>
Re: running suid programs (M.J.T. Guy)
Re: Sendmail in Perl32/NT <mark@imp.net>
Re: Sysadmin struggeling with PERL/Sed and etc... <rjk@coos.dartmouth.edu>
Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ (Daniel P. B. Smith)
Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ (Daniel P. B. Smith)
Trouble with shebang line ... <cbriese@earthlink.net>
Re: Trouble with shebang line ... <danboo@negia.net>
Re: Using strict and -d together (M.J.T. Guy)
Variable Interpolation inside regular expression <ascendr@intergate.com>
Re: verifying email address -- how? <rjk@coos.dartmouth.edu>
Re: What does this mean =~ ? <sneaker@mediaone.net>
Re: What does this one liner do? <scribble@pobox.com>
Re: What does this one liner do? <scribble@pobox.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Mar 1998 20:59:34 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: an extension question
Message-Id: <6fpm6m$p3l@fohnix.metronet.com>
doug@mcs.com (Douglas Harvey) wrote:
) I've written a perl extension to an existing set of "C" library
) routines that we use at work. It is very useful, but a little
) slow. One of the "C" routines returns a pointer to a buffer.
Ugh.
) I noticed that the perl internal routines make a copy of this
) buffer. This routine is called for each record we process, which
) can be millions, tens of gigabytes of data.
Yes, other than the time involved, that is the best way to
get Perl to handle stuff allocated by others [ie. let Perl
allocate its own copy]. There are a few other strategies
that have different trade-offs.
) I also noticed that the perl internal routines also always put a
) NULL at the end of the data buffer associated with (say) a scalar.
It is just defensive programming. That shouldn't hurt since it is
doing it to the copy of the buffer. Don't do this to the original
buffer, of course. Perl doesn't depend on it being there, it just
knows that a lot of C code can misbehave if there isn't eventually
a '\0'.
) Any opinions on the wisdom of simply having the perl scalar point
) to the "C" data buffer (possibly without a terminating NULL).
Depends on what you mean by this. Unless you side-step all of the
Perl macros that are there to prevent you from doing such a thing,
you can't tell a scalar to use a specific buffer.
The reason for this is that Perl will want to reallocate the
buffer if that scalar gets assigned a longer value or free the
buffer when that scalar is destroyed. Perl is probably using
either its own version of malloc() or at least a "safe" wrapper
around malloc() so that it will complain [or worse] if it tries
to free a buffer that some other code allocated.
A different way to have a scalar point to a buffer that Perl didn't
allocate that _is_ supported, is to have the scalar allocate it's
own 4-byte (for example) buffer and stuff the value of the pointer
to the other buffer in there. Then you can use unpack("P$len",...)
to extract data from the buffer for use by Perl. For most cases,
this still eventually involves copying the data, but that is just
the way Perl does things. For your particular case, it might be
a much more acceptable solution or may be almost as bad. For
example, if you mostly just pass this pointer back into the C
routines, then no copying of the buffer would ever be done.
) One more thing: I noticed that there is a flag that can be set on
) a perl variable to make it read-only. I am not aware of how this
) can be done within a perl program and would like to hear of how
) anyone has made use of this. For example, in the above situation,
) should I make the scalar pointing to the "C" buffer read-only.
One way to do it in Perl is to use an extension that uses C code
to set this. I don't recall the name, but I'm pretty sure that
that module has already been written.
Doing this in your XS code would probably eliminate the problem of
Perl wanting to reallocate the buffer that doesn't belong to it.
But it probably leaves the problem of Perl wanting to free the
buffer. You could just code carefully to avoid this problem. But
it wouldn't be something you should do in a module that you expect
other people to use.
There should be [and might be by now] a way to tell Perl not to
use its default routine for freeing scalar value buffers. My
quick attempts to find it did lead me to believe that the only way
this would be supported is via "magic". I'm a little familiar
with the general idea behind "magic" [which means something fairly
specific to Perl] and just re-read the section on "magic" in
perlguts.pod and a bunch of Perl source code, but I can't pretend
to be an expert on it.
If I had to implement this right now and copying the data buffer
with either of the two previously described supported methods was
truely unacceptable, then I'd try to:
* cheat and set the SV to just point at the buffer;
* mark the SV as read-only;
* set the reference count too high so Perl won't ever free it by
itself;
* add magic of type '~' so you tell these SVs from all other SVs;
* add a function to the XS code that checks for '~' magic with
the right name, removes the magic, frees the buffer, sets the
SV to think it doesn't need a buffer, then decrements the
refcount so Perl can free the SV when nobody is using it.
Utter simplicity, eh?
But what we really need is a new type of magic, say 'm', with a
new vtbl_malloc={0,magic_alloc,0,0,magic_free} which works like
'U' magic in that you specify your own versions of realloc() and
free() to be used instead of Perl's realloc() and free().
I just hope someone who knows a lot more about perl guts and magic
read this and can tell us all of the mistakes I made.
Good luck,
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: Tue, 31 Mar 1998 03:15:23 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: Date manipulations?
Message-Id: <tmorniniEqnyDo.Jo0@netcom.com>
Burt Lewis (burt@ici.net) wrote:
: I need to determine 2 dates based on today's date.
Try Date::Manip on CPAN. Don't know if it'll do it directly,
but from what I've read, if it can't do it, it can't be done. :-)
-- Tom Mornini
-- InfoMania
------------------------------
Date: Tue, 31 Mar 1998 00:12:29 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: debugging Perl
Message-Id: <35207B40.E6B5B9B9@coos.dartmouth.edu>
Ilya Zakharevich wrote:
>
> Jason Gloudon wrote:
>
> > The debugger can do everything you'd want.
>
> This is an overstatement. It has no up/down commands:
>
> It cannot examine lexicals of a different scope (feasible, but may
> imply a security risk), and will not show the "old" values of locals
> (not possible even from C).
And it can't preserve the value of $. :-)
--
_ / ' _ / - aka - rjk@coos.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: 31 Mar 1998 02:38:17 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: File IO Question: opening for appending without flock?
Message-Id: <6fpkup$2c0$1@lyra.csx.cam.ac.uk>
In article <351C58FE.73551852@hpl.hp.com>, Larry Rosler <lr@hpl.hp.com> wrote:
>It is not necessary to lock a file being appended to. The flock
>documentation is too conservative on this point; a better example would
>show a file being opened for read/write (+<...).
>
>The following description comes from my HP-UX manual fopen(3S), but the
>underlying behavior is guaranteed by the open(2) function in all ANSI-C
>compliant implementations:
>
>When a file is opened for append ... it is impossible to overwrite
>information already in the file. All output is written at the end of
>the file, regardless of intervening calls to fseek(). If two separate
>processes open the same file for append, each process can write freely
>to the file without fear of destroying output being written by the
>other. Output from the two processes will be intermixed in the file in
>the order in which it is written.
In practice, you'll usually get away with this. But note that the
interleaving is not defined - you might get a record from one process
in the middle of a record from another process. So strictly speaking
locking _is_ required.
Mike Guy
------------------------------
Date: 30 Mar 1998 22:31:35 GMT
From: ehood@medusa.acs.uci.edu (Earl Hood)
Subject: Re: file trees
Message-Id: <6fp6g7$l6r@news.service.uci.edu>
In article <35200AB1.7D37@min.net>, John Porter <jdporter@min.net> wrote:
>Robs hols wrote:
>> Can anyone suggest some perl code that would allow me to, given a particular
>> directory, list all files in that directory AND in all directories below it
>> (and all
>> directories below them etc. etc.)
>
>RTFFAQ. File::Find.
I do not think it is in the FAQ. And File::Find is somewhat kludgy
to just get a list of files. It is more suited for find(1) like
programs. Here is something that should do:
sub files_to_list {
my $dir = shift; # Starting point
my @ret = (); # Return list
my @flist = (); # Current file listing
local($_);
## Open directory
if (!opendir(DIR, $dir)) {
warn "Warning: Unable to open $dir: $!\n";
return ();
}
## Get files (exclude "." and "..")
@flist = grep { $_ ne '.' and $_ ne '..' } readdir(DIR);
close(DIR);
## Loop thru each file
my $file;
foreach (@flist) {
$file = "$dir/$_"; # Pathname of file
## If directory, recursive call to get file list
## (note, directory not part of return list)
if (-d $file) {
push(@ret, files_to_list($file));
next;
}
## If plain file, add to return list
if (-f $file) {
push(@ret, $file);
next;
}
## Skip any special files
next;
}
## Results
@ret;
}
--ewh
--
Earl Hood | University of California: Irvine
ehood@medusa.acs.uci.edu | Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME
------------------------------
Date: Mon, 30 Mar 1998 22:43:10 -0500
From: Stephen Mubita <smubit1@gl.umbc.edu>
To: CP <peredina@progress.com>
Subject: Re: free disk space
Message-Id: <Pine.SGI.3.96.980330224210.9081B-100000@foxtrot.gl.umbc.edu>
Thank you, thank you ! Just what the doctor ordered, and so prompt too !
On Mon, 30 Mar 1998, CP wrote:
=> Try the File module:
=>
=> use File::Df;
=>
=> I believe it will tell you all you need to know....
=>
=> -Curt
=>
=> Stephen Mubita wrote:
=>
=> > Dumb question, I fear. How can a perl script discover how much disk space
=> > is free on a drive / filesystem ?
=> >
=> > Thank you,
=> > Stephen
=> >
=> > Stephen Mubita smubit1@umbc.edu
=> > ======================================================================
=> > 'God opposes the proud, but gives grace to the humble.'
=> > James 3 : 6b
=> > ----------------------------------------------------------------------
=> > | UCS is not responsible for any opinions contained here |
=> > ====================******************************====================
=>
=>
=>
Stephen Mubita smubit1@umbc.edu
======================================================================
'God opposes the proud, but gives grace to the humble.'
James 3 : 6b
----------------------------------------------------------------------
| UCS is not responsible for any opinions contained here |
====================******************************====================
------------------------------
Date: Mon, 30 Mar 1998 05:16:20 GMT
From: troy@whadda.com (Troy Denkinger)
Subject: Hash Of Hashes vs. Hash With Split
Message-Id: <6fpui9$6gv$1@hirame.wwa.com>
While working with a database application, I started
thinking about different data structures.
Given data which will have a unique key and numerous other
discrete, associated pieces of data, what is the best
structure for storing that data in such a way that I can
efficiently access it again?
That is given this flat text file, fields delimited by
tildes, what is the best way to store it:
Titanic~1997~Cameron~10
Casablanca~1942~Curtiz~1
Where the fields are:
Title~Year~Directory~Oscars
I came up with the two solutions below. One uses a hash of
hashes and the other uses a simple hash that splits the
value to arrive at the various pieces of data associated
with the key.
Using Benchmark.pm, the hash of hashes option is more speed
efficient in retreiving the data.
My question is, are there other things I should consider
when deciding which approach to use?
While I've begun looking into perl guts, I don't fully
understand how these two constructs are handled by perl.
Thanks for any thoughts,
Troy Denkinger
--------------------------------------------
hashhash.pl
--------------------------------------------
#!/usr/bin/perl -w
use strict;
#use Benchmark;
use vars qw(%movie $key1 $key2);
$movie{'Titanic'}->{'Release Date'} = "1997";
$movie{'Titanic'}->{'Director'} = "Cameron";
$movie{'Titanic'}->{'Oscars Won'} = "10";
$movie{'Casablanca'}->{'Release Date'} = "1942";
$movie{'Casablanca'}->{'Director'} = "Curtiz";
$movie{'Casablanca'}->{'Oscars Won'} = "1";
#Benchmark code
#my $t = new Benchmark;
#$t = timeit(100, '
foreach $key1 (keys %movie)
{
print $key1."\n";
foreach $key2 (keys %{ $movie{$key1}})
{
print $key2.":
".$movie{$key1}->{$key2}."\n";
}
print "\n";
}
#');
#print timestr($t)."\n";
--------------------------------------------
hashsplit.pl
--------------------------------------------
#!/usr/bin/perl -w
use strict;
#use Benchmark;
use vars qw(%movie $key);
$movie{'Titanic'} = "1997~Cameron~10";
$movie{'Casablanca'} = "1942~Curtiz~1";
#Benchmark code
#my $t = new Benchmark;
#$t = timeit(100, '
foreach $key (keys %movie)
{
my ($release, $director, $oscarswon) = split /~/,
$movie{$key};
print $key."\n";
print "Release Date: $release\n";
print "Directory: $director\n";
print "Oscars Won: $oscarswon";
print "\n\n";
}
#');
#print timestr($t)."\n";
------------------------------
Date: 31 Mar 1998 02:14:32 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: help needed with grep type function for perl script.
Message-Id: <6fpji8$1rn$1@lyra.csx.cam.ac.uk>
Martin Vorlaender <MARTIN@RADIOGAGA.HARZ.DE> wrote:
>Benjamin Holzman (bholzman@mail.earthlink.net) wrote:
>: Well, of course, you _could_ use grep. Or, this:
>
>: open(FILE, "<filename") or die "Couldn't open filename: $!";
>: my $found_it = 0;
>: my $ip_to_find = '128.0.0.2';
>: while (<FILE>) {
>: if (/$ip_to_find/) {
>: print;
>: $found_it = 1;
>: last;
>: }
>: }
>: print "Couldn't find [$ip_to_find]." unless $found_it;
>
>or better yet, use /\Q$ip_to_find\E/, so '128a0b0c2' won't be matched.
Or better still, /^\Q$ip_to_find\E$/, so '128.0.0.23' won't be matched
either.
Mike Guy
------------------------------
Date: Mon, 30 Mar 1998 21:18:59 -0800
From: Larry Rosler <lr@hpl.hp.com>
To: "M.J.T. Guy" <mjtg@cus.cam.ac.uk>
Subject: Re: help needed with grep type function for perl script.
Message-Id: <35207CC3.10F455A5@hpl.hp.com>
> >: if (/$ip_to_find/) {
> >or better yet, use /\Q$ip_to_find\E/, so '128a0b0c2' won't be matched.
Or best of all, use
if ($_ eq $ip_to_find) {
which is what this comes down to!
Larry Rosler
------------------------------
Date: Mon, 30 Mar 1998 21:12:34 -0800
From: Larry Rosler <lr@hpl.hp.com>
To: "M.J.T. Guy" <mjtg@cus.cam.ac.uk>
Subject: Re: help needed with grep type function for perl script.
Message-Id: <35207B42.EC27E206@hpl.hp.com>
M.J.T. Guy wrote:
>
> Martin Vorlaender <MARTIN@RADIOGAGA.HARZ.DE> wrote:
> >Benjamin Holzman (bholzman@mail.earthlink.net) wrote:
> >: Well, of course, you _could_ use grep. Or, this:
> >
> >: open(FILE, "<filename") or die "Couldn't open filename: $!";
> >: my $found_it = 0;
> >: my $ip_to_find = '128.0.0.2';
> >: while (<FILE>) {
> >: if (/$ip_to_find/) {
> >: print;
> >: $found_it = 1;
> >: last;
> >: }
> >: }
> >: print "Couldn't find [$ip_to_find]." unless $found_it;
> >
> >or better yet, use /\Q$ip_to_find\E/, so '128a0b0c2' won't be matched.
>
> Or better still, /^\Q$ip_to_find\E$/, so '128.0.0.23' won't be matched
> either.
>
> Mike Guy
Or better still, /^\Q$ip_to_find\E$/o, so the regex won't be compiled
for every line in the input.
Larry Rosler
------------------------------
Date: Tue, 31 Mar 1998 05:43:30 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <35208116.17EB@mediaone.net>
Mark Stackhouse wrote:
>
>
> To those interested, Sneex is asking for our input on a
> Newbie chat group and an AutoFAQ. See: Announcement (Re:
> was (Calling all Newbies)).
> Sneex is knowledgeable AND a class A-1 guy (see his posts
> here). He is also a system admin so whatever is done will
> be done professionally :-)
> If you're really interested in learning Perl without being
> brain bashed,
> please give him your support.
With ONLY three respondents I don't think the proposal is going to work
out... But, it's only been three days...
PS - I am still a newbie, but I appreciate the vote of confidence Mark
:-)
Sneex
------------------------------
Date: 31 Mar 1998 02:11:17 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Kill Signals going to forked System command not Perl script
Message-Id: <6fpjc5$1o1$1@lyra.csx.cam.ac.uk>
In article <01bd5386$954e1f50$4331aecc@siemens>,
Curtis Siemens <siemens@digitalcourier.com> wrote:
>I'm have a problem where kill signals (UNIX, Data General - DG-UX) kill
>the forked process from the system command within my perl script,
>and therefore don't go to my perl signal handler. This is causing my
>perl script not to clean things up properly.
This is a fundamental UNIX restriction. UNIX has a choice:
is the Right Thing to send the signal to the parent or the child?
And the answer depends on whether the child is interactive or not.
If the child is interactive (like vi or more), you want the child to
get the signal. If not, you usually want the parent to get the signal.
But there's no general means of knowing whether the child is
(intended to be) interactive. So UNIX arbitrarily chooses to hit
the child in all cases.
This choice does have the advantage that the parent can fix up the
situation. After a system() call, $? indicates whether the child
was terminated by a signal. So you can write code like
system("cat bla bla bla > /tmp/temp.file");
my $sig = $? & 0x7f;
kill $sig, $$ if $sig;
to activate your signal handler.
See perldoc -f system for more details.
Mike Guy
------------------------------
Date: 30 Mar 1998 22:10:23 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Pat Trainor <ptrainor@bbn.com>
Subject: Re: math: random numbers.. well, sorta-kinda..
Message-Id: <8cg1jzxx6o.fsf@gadget.cscaper.com>
>>>>> "Pat" == Pat Trainor <ptrainor@bbn.com> writes:
Pat> Quasi-Random Number Generation with Perl - a "seedy" business..
Pat> I have found that to generate a random image is easy. The hard
Pat> part is to control how un-random a random number can be. What?
Pat> If I want to display help messages randomly, and already know the
Pat> most common, I need a way to mathmatically display certain files more
Pat> often than others, preferrably under very calculated means.
I have a sample of generating a weighted random selection in
column #9 ("number 9... number 9..." :-) of my WebTechniques columns
archived online at http://www.stonehenge.com/merlyn/WebTechniques/.
Check it out.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 154 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 31 Mar 1998 00:50:20 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: MSEXCHANGE / OUTLOOK
Message-Id: <35208422.BB85D17A@coos.dartmouth.edu>
Pascal AMRAM wrote:
>
> Subject: MSEXCHANGE / OUTLOOK
So here I am trying to figure out what an M sex change is....
--
_ / ' _ / - aka - rjk@coos.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: 31 Mar 1998 04:35:08 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: Need help with "shared memory" module IPC::Shareable !
Message-Id: <891319321.397146@thrush.omix.com>
Mark Seuffert <captain@pirate.de> wrote:
: Thanks for your help.... but I think in modules the use of 'croak' to
: handle run-time problems is very user unfriendly!!!!!
Like I said, it depends on the usage. If you're going the OO
route anyway, exceptions oftin make the most sense IMO. If you're
writing normal functions, exceptions normally don't make sense.
For good or bad, OO code oftin calls lots of other OO code that
my called be deep in other peoples classes and anything along the
line could have a bug in a particular use. At this point, a full
stack trace is most oftin one of the best debugging tools available.
The only way to cleanly get the *full* stack trace is to through an
exception.
: There are some reasons for me to think this is a bad style:
: (plz tell me if I'm wrong)
No, you're not wrong. Like I said, simple functions rarely have any
business throwing exceptions.
: 1. U have to call all module functions with the try'n'catch method.
Ah, but that's my point. Methods more oftin then functions
need exceptions.
: Would U also like to use normal perl functions as try'n'catch? Than U
: have to open a file with
: eval { open (FILE, $file) }; if ($@) { die "Can't open $file: $@\n" }
: instead of open(FILE, $file) || die "Can't open $file: $!\n";
Which, I agree would be quite lame.
: So why do module programmers make life more complicate, are they enemies
: of Larry?
Yes. :-)
: 2. If U work with tied variables (like in module IPC::Shareable), U have
: to 'eval' every time U work with these variables. Isn't that really
: stupid?
Actually, no I don't think so. When most (all?) of the DBM modules
have a problem durring use (non-creation) they throw an exception.
Try storing a 2k string in an NDBM value and see how fast your
script dies. :-)
IMHO, the call to tie() should not throw an exception, however any
problems from that point on should throw an exception. It would be
more lame to write code like:
$MY_SHM_VAR{foobar} = 'dog'
or die qq(Error: $IPC::Shareable::Error, stopped);
Not only is the code ugly, you still don't get a stack trace. Also,
remember that you don't have to eval() each use by itself. You can
wrap large blocks easily:
sub mySub {
my $foo = shift;
eval {
...lots of stuff with the tied vars...
#
#
#
#
...that might throw an exception...
};
$Error = $@; # A package global error var, used like $!
return if $@;
return 1;
}
: At some points of my scripts I avoid 'eval' by catching now
: $SIG{'__DIE__'} and try to find out if IPC:Sharable called an 'croak'.
I still would like an answer if the use of __DIE__ and __WARN__
suffer from the same major problems that the use of any "real"
signals have when used in perl. -Perl signals are vary, vary
unsafe for any use...
: To make IPC::Shareable work I used the script below... maybe someone
: could help me to make it better! If shared memory is working with perl
: there is no need for some socket solutions. Who says perl can't do
: complex multithreaded shared-memory applications (only the FAQ)... :)
There still are strong reasons not to use shared memory. There
are limits on how many shared memory handles can be used at once
on any given system. There are security issues with using them.
Bugs in code and interrupted programs can cause memory "leaks" that
affect the entire system by never releasing the memory. -Yes, you
can delete them manually, but that's a bandaid.
: # Set up error handlers
: sub catch_int { exit; } #Note: Catch any other signals like this
: $SIG{INT} = \&catch_int;
This is the default for SIGINT anyway. No need to set it.
: eval { tie($scalar, IPC::Shareable, $glue, { %options }) };
I agree, tie() should not throw exceptions, least of all croak()
unless it's *only* a problem of invalid arguments being passed to
tie().
: # Free our 'shared memory block' (try'n'catch)
: eval { untie $scalar };
Ditto.
: $SIG{INT} = \&Exit_handler_to_shutdown_whatever;
BTW, what about SIGTERM? If you catch SIGINT, you should probably
be catching SIGTERM the same way. Perl signals being vary shakey
in general not withstanding...
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 30 Mar 1998 22:58:01 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: proposal: while $line (<FILE>)
Message-Id: <6fpt4p$hta@tekka.wwa.com>
mike@stok.co.uk writes:
>Tushar Samant <scribble@pobox.com> wrote:
>
>>How can listing a man page be an answer to a *proposal*?
>
>It might point out that there is existing documented behaviour, and that
>the proposal addresses a very small grey area and might do more harm than
>good (in my opinion). Maybe the reply was written with the intent of
>making the original poster review the documentation and consider whether
>they thought perl was already adequate in the area in question.
That's true, it would. However, I felt that he had done a very good
job of doing his homework, and I personally think it's quite reasonable
to ask for "while $line (<FILE>)" behaviour. In fact I think it is crazy
that "while ($line = <FILE>)" (legal syntax) behaves differently from
"while (<FILE>)".
------------------------------
Date: 31 Mar 1998 04:11:26 GMT
From: Jamie Hoglund <jhoglund@mirage.skypoint.net>
Subject: Re: Public Key Encryption (non pgp)
Message-Id: <6fpqde$8mg$1@shadow.skypoint.net>
Jamie Hoglund <jhoglund@mirage.skypoint.net> wrote:
Hate to followup to my own followup, but there are many reasons PGP isn't
acceptable for this, one of them is the fact that it isn't always
available, (and in fact usually isn't in this case. It's for people who
don't have the inclination to install PGP on their systems, and various
cranky ISP's that refuse to have it.) These issues are beyond my control,
so there is really nothing I can do about it.
Transfering the data isn't a problem, it's storing it that has me worried.
Jamie
------------------------------
Date: 31 Mar 1998 02:33:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: running suid programs
Message-Id: <6fpkmj$2b6$1@lyra.csx.cam.ac.uk>
<nmcfadye@mae.carleton.ca> wrote:
>I have just installed perl5 004. I noticed that there were a bunch of
>questions relating to suid oepration during installation which I didn't really
>understand. I have program called fping which is an suid program. I can run
>it from a sh or csh but if I try to run in my perl script I get a error
>message, must be run or root
>It seems perl doesn't make use of the suid permission on fping. Can this be
>fixed without recompiling perl again.
This is explained in the perlsec man page, under the heading
"Security Bugs".
Mike Guy
------------------------------
Date: Mon, 30 Mar 1998 21:33:37 -0500
From: "Mark Polakow" <mark@imp.net>
Subject: Re: Sendmail in Perl32/NT
Message-Id: <6fplon$buk$1@viper.america.net>
Sendmail has a Windows port that works with an smtp server. Or you can use
Blat which is a windows sendmail emulator.
Nuttapong Tungdajahirun wrote in message ...
>I 'm just changing to Perl32.
>
>What can I use instead of sendmail in UNIX in my perl script for Perl
>32?
>Please give me some example.
>
>I'm using NT w/ IIS 4.0.
>Thanks
>
>Jeen
>
>
>
------------------------------
Date: Tue, 31 Mar 1998 00:32:18 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Sysadmin struggeling with PERL/Sed and etc...
Message-Id: <35207FE7.96EB8C04@coos.dartmouth.edu>
Joergen W. Lang wrote:
>
> [Rewritten marge.pl, with efficiency in mind]
> [...]
> OUTER: while (<FILE_1>) {
> chomp;
> print NEWFILE;
> while (<FILE_2>) {
> print NEWFILE;
> next OUTER;
> }
> }
> [...]
>
> Better ?
Much better! Somehow, I'd forgotten about chomp in my solution; I foolishly
used tr/// instead.
I must say the inner while loop, with the automatic next of the outer loop,
seems a little weird. I guess you just wanted to avoid explicitly naming any
variables in that section. :-)
--
_ / ' _ / - aka - rjk@coos.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: Tue, 31 Mar 1998 02:51:54 GMT
From: dpbsmith@world.std.com (Daniel P. B. Smith)
Subject: Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ
Message-Id: <EqnxAI.F2x@world.std.com>
In article <6foj26$b7p$1@marina.cinenet.net>,
Craig Berry <cberry@cinenet.net> wrote:
>One of the more useful factoids I've encountered is "pi seconds is a
>nanocentury." It's easy to remember, accurate to well within 1%, and
>makes long-interval time calculations in seconds easier to do in your
>head.
It was recently pointed out to me that "one furlong per fortnight"
is almost exactly 1 centimeter per minute. How's that for useful?
And, of course, "in fourteen hundred and ninety two/Columbus sailed
the ocean blue/Divide the son-of-a-bitch by two/And that's how many
watts are in a horsepower."
--
Daniel P. B. Smith
dpbsmith@world.std.com
------------------------------
Date: Tue, 31 Mar 1998 03:00:59 GMT
From: dpbsmith@world.std.com (Daniel P. B. Smith)
Subject: Re: The "Y2k-bugs-are-not-just-a-legacy-problem" FAQ
Message-Id: <Eqnxpn.J23@world.std.com>
In article <6fov48$kmr$1@xs2.xs4all.nl>,
Zooko Journeyman <zooko@xs4all.nl> wrote:
>Theran Cochran <theranc@geocities.com> wrote:
>>
>>There are 136.192 years in a 32 bit field though (hence the year 2036
>>bug in most Unix programs, or is that year 2106? I can't remember), and
>>584,942,417,355.1 years in a 64 bit field. Or about 100,000 times as
>>long as multicellular life has existed on earth, plus a month to
>>recompile all your programs to 128 bit date fields.
>
>
>This is assuming, of course, the we fix that "cold death of
>the universe" bug before then.
Not to worry. After all, the continents only started drifting within the
last couple of decades (when I was in high school, it wasn't that they
did know the continents drifted: they DID know that they DIDN'T drift.)
And my brother got lectured for wasting good food because he would cut off
the half inch of fat around the edge of his lamb chops, while I was the
good little boy and ate it all up.
I believe the universe was in continuous creation then. Although I do
think the earth had moved from the center of the galaxy, where it was
maybe as recently as the thirties, out two-thirds of the way from the rim,
where I believe it still is today.
Cosmology will change polarity a few times before the last bits
flip.
Some say the world will end in fire, some say in ice...
--
Daniel P. B. Smith
dpbsmith@world.std.com
------------------------------
Date: Tue, 31 Mar 1998 03:32:14 +0000
From: Craig Robert Briese <cbriese@earthlink.net>
Subject: Trouble with shebang line ...
Message-Id: <352063BE.51FCC23B@earthlink.net>
When i place the line in my perl scripts that indicates where the
interpreter is, it doesn't seem to be recognized. When i enter the
command:
% perlscript.pl
i get perlscript.pl: Command not found. Yes, the file is executable,
and Yes, i have the correct path for the interpreter. If anyone has
any suggestions as to what it might be that i am over-looking, they
would be appreciated.
thanks,
Craig Briese
------------------------------
Date: Mon, 30 Mar 1998 23:01:30 -0500
From: Dan Boorstein <danboo@negia.net>
To: Craig Robert Briese <cbriese@earthlink.net>
Subject: Re: Trouble with shebang line ...
Message-Id: <35206A9A.30081236@negia.net>
Craig Robert Briese wrote:
>
> When i place the line in my perl scripts that indicates where the
> interpreter is, it doesn't seem to be recognized. When i enter the
> command:
>
> % perlscript.pl
is . part of your path? try:
% ./perlscript.pl
hope this helps,
dan
------------------------------
Date: 31 Mar 1998 02:27:44 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Using strict and -d together
Message-Id: <6fpkb0$23k$1@lyra.csx.cam.ac.uk>
Jete Software Inc. <jete@dgs.dgsys.com> wrote:
>I am running perl 5.003
>
>When I attemt to run my perl program with the following lines
>
>#!/usr/local/bin/perl -d
>
>use strict;
>
>I get the following error message:
>
>Undefined subroutine &Carp::longmess called at /usr/local/src/perl-5.003/lib/per
>l5db.pl line 1361.
I can't reproduce this effect, but I presume that some other line in
your code violates "use strict" and generates an error message.
Debug catches this and tries to print a backtrace; it needs the Carp module
to do this. So put "use Carp;" right after the "use strict;".
Mike Guy
------------------------------
Date: Mon, 30 Mar 1998 21:46:52 -0600
From: "ascendr" <ascendr@intergate.com>
Subject: Variable Interpolation inside regular expression
Message-Id: <6fpovm$phc@mercury.hiline.net>
Unix versus DOS.
Why will both of the scripts below work on Win32 but only the list one works
in UNIX, AIX specifically?
Any ideas ?
@test = ('CUED', 'Black', 'Blue', 'BLAST', 'Somewhere', 'TEST', 'theast');
@filterlist = ('ED', 'EST');
foreach $filter (@filterlist) {
foreach $t (@test) {
if ($t =~ /$filter/) {
print "found $filter in $t\n";
last;
}
}
}
# test.prt contents are below
# CUED
# Black
# Blue etc ...
#
# filter.att contents are below
# ED
# EST
# no surrounding apostrophes ...
open TESTFILE, "test.prt";
@test = <TESTFILE>;
chomp @test;
open FILTER, "filter.att";
@filterlist = <FILTER>;
chomp @filterlist;
foreach $filter (@filterlist) {
print "filter = $filter\n";
foreach $t (@test) {
print "t = $t\n";
if ($t =~ /$filter/) {
print "found $filter in $t\n";
}
}
}
------------------------------
Date: Tue, 31 Mar 1998 00:18:47 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: verifying email address -- how?
Message-Id: <35207CBB.20A3A47A@coos.dartmouth.edu>
John Moreno wrote:
>
> Anonther valid use is mail and news programs - some of the incorrect
> addresses can be lethal to programs which hasn't anticipated them, and
> sending mail (evil) or news (bad) with munged addresses isn't good to
> start with, causing the other persons machine to crash and burn to boot
> is downright uncivilized.
Okay, I find munged addresses pretty darn annoying, and I won't bother
unmunging an address to send an email reply. But I find the above argument
against munging addresses to be rather silly. If someone is using a buggy
program that crashes on a bad email address, that's their problem. One thing
we shouldn't have to do is compose our posts to conform to potential bugs in
miscellaneous news readers.
--
_ / ' _ / - aka - rjk@coos.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: Tue, 31 Mar 1998 05:35:54 GMT
From: Sneaker's Nest <sneaker@mediaone.net>
Subject: Re: What does this mean =~ ?
Message-Id: <35207F4E.22D4@mediaone.net>
John Porter wrote:
>
> Webmaster wrote:
> >
> > I would hazard a guess that it means perform the requested operation
> > and then store the results here.
>
> Hazard away, doofus. It doesn't mean anything about storing
> anything anywhere. Any "storing" it does is as side-effects.
>
> John Porter
Sorry I'm late getting back :-)
I believe Bite Me! is appropriate here :-)
Sneex ;-)
------------------------------
Date: 30 Mar 1998 22:04:46 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: What does this one liner do?
Message-Id: <6fpq0u$bn2@tekka.wwa.com>
rootbeer@teleport.com writes:
>> The point, of course, is not whether the piece of info is available
>> at the end of an easy or difficult scavenger hunt. It's whether it's
>> REASONABLY available.
>
>In this case, the author of the question didn't even _try_ reading the
>docs before posting. So, no matter how well-written the docs are, they
>didn't help. :-(
In retrospect, in this specific case I will agree.
>> Everyone will agree that "what's there in the source code that you
>> don't understand" is an unreasonable response to a question.
>
>No, it's not unreasonable. (Even if it's misquoted. :-)
I was giving an example of something that's obviously unreasonable.
I wasn't quoting you.
>Of course, I'm always interested in finding ways that my answers could be
>more complete and helpful. If you have suggestions on better ways I could
>have answered this (or any other) questions, please let me know. Thanks!
Actually, *I* am thinking of setting up (what else but) a web page
with a rather different sort of "FAQ", maybe even something inter-
active, which is like a non-judgemental counseling center. Now who
on earth would fry their minds doing that... Nobody. It would just
give repetitive answers, point to FAQs etc.
I am completely vague about it right now, and I was going to ask
people about ideas about how to answer the "annoying" questions
we see on the group. But I am afraid ...
------------------------------
Date: 30 Mar 1998 22:36:06 -0600
From: Tushar Samant <scribble@pobox.com>
Subject: Re: What does this one liner do?
Message-Id: <6fprrm$fbm@tekka.wwa.com>
rjk@coos.dartmouth.edu writes:
>Personally, I'll cite page numbers of whatever book I feel answers the
>question at hand. (Effective Perl Programming, for example, was published by
>Addison Wesley.) Your policy would seem to imply that referring someone to an
>encyclopedia would be in poor taste. Perhaps a better example; referring
>someone to a page in Data Structures and Algorithms, by Aho, Hopcroft, and
>Ullman.
Well I have seen citations without any *substance* being quoted.
And secondly, it's sort of accepted that compiling is an elite
art, learning which needs apprenticeship and outlay. Perl's
culture always struck me as very pro-usenet and anti-guild...
Don't get me wrong, I am not against quoting from books.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 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.
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 2213
**************************************