[21723] in Perl-Users-Digest
Perl-Users Digest, Issue: 3927 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 7 03:06:34 2002
Date: Mon, 7 Oct 2002 00:05:10 -0700 (PDT)
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, 7 Oct 2002 Volume: 10 Number: 3927
Today's topics:
Re: Dealing with database problems gracefully? <dgardiner@houston.rr.com>
Re: Eliminating right-end whitespace <vm.mayer@comcast.net>
Re: finding processes <goldbb2@earthlink.net>
Re: finding processes <nospam@rostie.net>
Re: finding processes <nospam@rostie.net>
Re: finding processes (Alan Barclay)
Re: How to find array element index efficently <goldbb2@earthlink.net>
How to get time in with millisecond precision (Brett)
Re: How to get time in with millisecond precision <goldbb2@earthlink.net>
Re: ithreads, perl 5.8 and shared objects <goldbb2@earthlink.net>
Re: ithreads, perl 5.8 and shared objects <goldbb2@earthlink.net>
Re: Kill current process(es) <garry@ifr.zvolve.net>
needleman-wunsch alignment (Stanley Lee)
Re: needleman-wunsch alignment <goldbb2@earthlink.net>
Re: One line to Segfault Perl <cpryce@pryce.nospam.net>
Re: Sharing a program? <jkeen@concentric.net>
Simple Win32 batch file gives errors <dcpope@sbcglobal.net>
Re: Simple Win32 batch file gives errors <wyzelli@yahoo.com>
Re: || versus OR <wksmith@optonline.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 07 Oct 2002 04:30:44 GMT
From: "Doug" <dgardiner@houston.rr.com>
Subject: Re: Dealing with database problems gracefully?
Message-Id: <U58o9.113535$121.2479376@twister.austin.rr.com>
What kind of database and how are you interfacing it? via modules?
I use DBI for connection to the database I use and not only are there
switches to pass to the database, but also a set of procedure calls to get
the error from a database, not only for checking the connection, but why it
failed if it failed.
However, I only know DBI, and a limited knowledge on it.
There are other modules avialable as well as database formats.
"Ron Reidy" <rereidy@indra.com> wrote in message
news:3DA0C474.752CA96F@indra.com...
> Simon Harvey wrote:
> >
> > Hi all,
> >
> > I'm doing aproject on behald of my students union. We have a database
that
> > we dont actually control but has kndly been provided by the university
> > itself.
> >
> > The downside of that is that we will never know if it is going offline.
This
> > led me onto the question of dealing with errors more genrally in perl,
on
> > which there seems to be very little external comment or documentation.
The
> > official docs are there and are very good (as always) for people who are
> > good at perl already (not really me), but what would help would be a
> > discussion of the features and perhaps a faq and tutorial. Something
that
> > newbies can get into. I sent this request to the perl faqs suggestions
page
> > but it doesnt seem that responsive as I know a few people also sent ina
> > similar request.
> >
> > Anyway, sorry about the rant. I do actaully have a question. I know a
little
> > bit about eval and was wondering if I should put my database related
calls
> > (such as making the initial connection and executing statements etc)
within
> > eval blocks?
> >
> > Someone told me that this was a bad idea before but then how else do i
make
> > the application robust? Its not that big a program but because it is
> > actually being deployed in a real world enviroment it absolutely must
have
> > error control.
> >
> > Another guy told me that evel was exctly what I should use so now I'm
all
> > confused!
> >
> > Does anyone have any thoughts or advise about anything above? Does
anyone
> > have the idea of the perl faq guys?
> >
> > I really think there should be an "Error Handling in Perl" faq (or
pehaps
> > just a section within a faq). Anything would be better than nothing
> >
> > Kind thanks to all who share their thoughts (and maybe even help me!!
:))
> >
> > Take Care
> > Simon
> Use eval {} blocks.
> --
> Ron Reidy
> Oracle DBA
------------------------------
Date: Mon, 07 Oct 2002 02:21:19 -0400
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: Eliminating right-end whitespace
Message-Id: <vm.mayer-D17F58.02211907102002@news-east.giganews.com>
In article <3d9fd640@news.victoria.tc.ca>,
yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote:
> Warren Block (wblock@wonkity.com) wrote:
> : Tassilo v. Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
> : That just gets rid of spaces, though, not all whitespace characters,
> : which would be
>
> : $string =~ s/\s+$//;
>
> You might want to use
> s/\s+?$//;
Aside from a slight runtime difference, is there
any functional difference between these two
regex's? I always use the former.
Thanks
mike
------------------------------
Date: Mon, 07 Oct 2002 00:38:15 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: finding processes
Message-Id: <3DA10FB7.58A4D981@earthlink.net>
Randy wrote:
>
> I am trying to write a perl script that will list all the PIDs of
> sendmail processes, and then print the working directory of each
> process.
use Proc::ProcessTable;
my $t = Proc::ProcessTable->new;
foreach my $p ( @{$t->table} ) {
next unless $p->cmndline() =~ /sendmail/;
# print $p->cwd(), "\n"; # not yet :(
my $pid = $p->pid();
print readlink("/proc/$pid/cwd"), "\n";
}
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 07 Oct 2002 04:47:10 GMT
From: Randy <nospam@rostie.net>
Subject: Re: finding processes
Message-Id: <g142qucgicufap5cfnflb3sghklrh64782@4ax.com>
On Sun, 06 Oct 2002 20:28:36 GMT, Steve Grazzini
<s_grazzini@hotmail.com> wrote:
> #!/usr/bin/perl -l
>
> foreach (`ps -ef`) {
> next unless /sendmail/;
> my (undef,$pid) = split;
>
> # that /proc stuff isn't portable, but:
> print "$pid: ", readlink "/proc/$pid/cwd";
> }
All I get is
server: >perl find-sendmail2.pl
15058:
The command 'ps -ef | grep sendmail' by itself returns:
root 15087 8971 0 23:46:04 pts/0 0:00 grep sendmail
So it is returning the PID of the perl script I guess.
------------------------------
Date: Mon, 07 Oct 2002 04:50:55 GMT
From: Randy <nospam@rostie.net>
Subject: Re: finding processes
Message-Id: <og42quc51m89msvcmgv6qr1uaj32g53fo6@4ax.com>
On Sun, 06 Oct 2002 23:04:50 GMT, "John W. Krahn" <krahnj@acm.org>
wrote:
>#!/usr/local/perl -w
>use strict;
>
>for my $s_pid ( map /(\d+)/, `ps -C sendmail -o pid` ) {
> my $link = readlink "/proc/$s_pid/cwd"
> or die "Cannot readlink /proc/$s_pid/cwd: $!";
> print "$link\n";
>}
Running this on Solaris, I get
ps: illegal option -- C
usage: ps [ -aAdeflcjLPy ] [ -o format ] [ -t termlist ]
[ -u userlist ] [ -U userlist ] [ -G grouplist ]
[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]
'format' is one or more of:
user ruser group rgroup uid ruid gid rgid pid ppid pgid sid
pri opri pcpu pmem vsz rss osz nice class time etime stime
f s c lwp nlwp psr tty addr wchan fname comm args
If I change ps to /usr/ucb/ps, I still get basically the same error
/usr/ucb/ps: illegal option -- C
usage: ps [ -aceglnrSuUvwx ] [ -t term ] [ num ]
------------------------------
Date: 7 Oct 2002 05:27:48 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: finding processes
Message-Id: <1033968584.629130@elaine.furryape.com>
In article <og42quc51m89msvcmgv6qr1uaj32g53fo6@4ax.com>,
Randy <nospam@rostie.net> wrote:
>>for my $s_pid ( map /(\d+)/, `ps -C sendmail -o pid` ) {
>Running this on Solaris, I get
>ps: illegal option -- C
-C is a Linux ps option, selects only programs that match
the string.
------------------------------
Date: Mon, 07 Oct 2002 00:18:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to find array element index efficently
Message-Id: <3DA10B33.9BCE0B9B@earthlink.net>
Darek Adamkiewicz wrote:
>
> Hello folks
> The following subroutine works for me but it's terribly slow
> - but it has some flexibility I'd like to retain:
> sub k2i {
> my ($keys, $args) = @_;
> my %conv = ();
> @conv{ @$keys } = (0..$#{$keys});
> return wantarray ? @conv{@$args} : $conv{$args->[0]};
> }
If you don't want a list, then don't calculate all of the indices:
sub k2i {
my ($keys, $args) = @_;
if( wantarray ) {
my ($i, %conv) = 0;
$conv{$_} = $i++ for @$keys;
@conv{@$args};
} else {
my $i = 0;
my $arg = $$args[0];
for( @$keys ) {
return $i if $_ eq $arg;
++$i;
}
undef;
}
}
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 6 Oct 2002 21:03:05 -0700
From: brettr1974@hotmail.com (Brett)
Subject: How to get time in with millisecond precision
Message-Id: <58a3c519.0210062003.2f3c9519@posting.google.com>
I need to calculate a time between two events. The thing is I would
like to do this with millisecond precision. I have had a look at some
time moduleson CPAN but couldnt find one that helps.
Is this possible ?
thanks
Brett
------------------------------
Date: Mon, 07 Oct 2002 00:19:23 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to get time in with millisecond precision
Message-Id: <3DA10B4B.B04F32C@earthlink.net>
Brett wrote:
>
> I need to calculate a time between two events. The thing is I would
> like to do this with millisecond precision. I have had a look at some
> time moduleson CPAN but couldnt find one that helps.
> Is this possible ?
Time::HiRes
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Sun, 06 Oct 2002 22:15:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <3DA0EE25.6A260E4C@earthlink.net>
Derek Thomson wrote:
> Uri Guttman wrote:
> >Derek Thomson wrote:
[snip]
> > > (BTW it doesn't matter if GUI events are blocking or not, you need
> > > a hook in your event loop so that "select" returns when a GUI
> > > event *happens*!)
> >
> > nope. you USE the event loop of the gui itself. this is simple to
> > do. then it handles all of the GUI events as well as your own.
>
> But you need to integrate your infrastructure's select loop with the
> GUI event loop.
That's easily done -- all GUIs that I know of allow you to put your own
callbacks for readyness of your own filehandles, and install your own
timeouts and callbacks. So "your" event loop really just calls the
GUI's event loop.
> Otherwise select won't return when a GUI event occurs!
If your event loop were trying to detect GUI events with select, then
indeed you would have this problem. But since you're having the GUI's
own event loop detect *your* events, this is not a problem.
> Unless of course, you put the GUI in another process.
The only time there's a need for that if your GUI doesn't allow you to
register your own filehandles to be watched, and your own timeouts.
[snip]
> > > No, that's not true. If two *processes*, or threads, are
> > > writing to a file (for example), there must be some form of
> > > locking to avoid race conditions. You can't avoid it.
> >
> > nope. if they share a file object (in a remote proxy process) then
> > file access could be single threaded.
>
> So, you've serialized it! What do you think locking is? Having a
> single threaded process that serializes access is a lock by another
> name.
Sure, but it's far easier to serialize it by having it all done within
one process, than to serlialize it by using locks and semaphores.
In fact, if you want an event based system, you almost *have* to do
serialization that way, unless you can create an 'acquired lock' event.
> > > Imagine one process is adding a record to a file. Halfway through,
> > > another process is scheduled, which starts writing to that same
> > > file. That process completes writing its record, then the first
> > > process gets to complete its write. Now you've got half a message,
> > > then a complete message, then the rest of the message ie a
> > > complete mess. You need locks to ensure mutual exclusion.
> >
> > nope. you just deal with file proxies to serialize access.
>
> So, you've serialized it, using a "proxy" to control access ie a lock.
A "lock" is a name for a specific way of ensuring serialization.
But not all forms of serialization are "locks".
Consider the task of keeping burglers from entering through your front
door -- you could use a lock, or you could put up a barricade. The most
common way is to use a lock. Should we then call barricades "locks"?
> > > Your remote file module will inevitable have to add a lock, or
> > > transactions, of *some* kind.
> >
> > nope.
>
> Please, you just admitted as much. How do you avoid the race condition
> otherwise? You need to ensure mutual exclusion.
You're both being silly. With message passing, yes, you would be using
transactions of a sort. But you wouldn't be using any kind of lock.
> > > I'll put this as gently as I can - why would I want any of that,
> > > when I *already* have CORBA/J2EE? What problem does all this stuff
> > > solve, except the vendor's need for customer lock-in on their
> > > ill-conceived proprietary junk written by god-knows who?
> >
> > it is much faster to develop message passing systems than comparable
> > rpc based ones. check out all the MOM systems out there.
>
> Like what? I tried thinking of something I could build with messages
> that have no acknowledgement, and couldn't. How do you know when
> something failed? And right away ... not when some admin notices that
> things have gone pear-shaped.
Who says that no acknoledgement would ever be needed? But the thing is,
if you recieve the acknoledgement with what you call a "reactive"
message handler, you can have a single-threaded, message passing based
system.
> And why are they "faster to develop". Is there any evidence of this?
> I'm pretty fast, too, you know ;)
Dealing with threads can produce some very subtle effects, which aren't
obvious at first, but which make debugging your program once it gets big
into a kind of hell.
If each process runs in one thread, it's far far easier to handle.
[snip]
> > > I already have perfectly good messaging services that are
> > > well-defined, and designed by sensible people via a public
> > > process, that run on top of CORBA/J2EE, if messaging is *really*
> > > what I want (ie my problem is inherently so loosely coupled that I
> > > don't need to know if anyone actually receives any of these
> > > messages. I'm not sure what that would be, though. MP3 swapping?)
> >
> > rpc can't do true message passing. tell me how you do this:
> >
> > take a single complex user request, break it up into multiple
> > parallel requests to the same DB (and even other servers) and wait
> > until all of them are completed, then send the combined results back
> > to the user. with threads you are forced to serialize all the
> > requests or spend half your code synchronizing them. with stem this
> > is trivial as parallel access is built in to message passing and the
> > gather module will synchronize the results coming back.
>
> With an event service? This provides everything you could ever want.
> You can register publishers and subscribers, and the rest is as you
> describe.
It sounds like you're suddenly advocating a message-passing system to
send data amongst your threads.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Sun, 06 Oct 2002 22:47:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <3DA0F5B1.5FD3291F@earthlink.net>
Derek Thomson wrote:
> Benjamin Goldberg wrote:
> > Derek Thomson wrote:
> >>Uri Guttman wrote:
> >
> > [snip]
> >
> >>>and what do you mean by the server calling itself directly or
> >>>indirectly?
> >>
> >>Let's say a client calls method 'foo' on object 'A' in one process.
> >>Method 'foo' now calls method 'bar' on object 'B' in another
> >>process. As part of the execution of method 'bar', method A.fubar is
> >>called. As A.foo is already being handled in A's process, we have a
> >>deadlock situation.
> >
> >
> > Not necessarily... Look at it like this... suppose when the first
> > process does:
> >
> > my $result = $B->bar(@args);
> >
> > It really does:
> > my $result;
> > send_message( $B, "bar", \@args );
> > RPCLOOP: {
> > my $event = get_next_event();
> >
> > # ->fubar, in this process, will be called from here:
> > $event->dispatch(), redo RPCLOOP
> > if $event->type() ne "response";
> >
> > $result = $event->data();
> > }
> >
> > Note that while waiting for a response, it is *not* waiting *only*
> > for a response to $B->bar, but it is also dispatching other
> > requests, too!
>
> Yes, I believe that's what I'd call "reactive". Somewhere in the
> dispatch, you'll probably call "select", unless of course you want
> your process to busy-wait, but that's your choice ;)
Yeah... so what? It's still a message passing system, using only a
single thread and a select loop. The only peculiarity is that the
select loop has multiple entry points -- any place that wants an
acknoledgement to a message enters the select loop as a subroutine call.
> >>The trivial (direct) case is when A.foo calls A.fubar directly, but
> >>that can be avoided by having the ORB (or whatever infrastructure)
> >>skip the message dispatch by detecting that it's a local call.
> >>That's impossible, however, in the indirect case described above.
> >
> > Even if it's not smart enough to skip the message dispatch, there
> > shouldn't be a deadlock, if the message dispatching is done as I
> > show above.
>
> I think we're agreeing violently.
Err, I'm saying that message passing can work without deadlocking. You
were saying that deadlocking is inevitable. Where's the agreement?
> >>>with message passing that is less than trivial, you just
> >>>send a message to yourself (or whatever). as for exploiting
> >>>parallelism the above mentioned project partly on a 4 way cpu and
> >>>it uses processes and message passing to get parallelism. in fact
> >>>when we added that feature, the time for a multiple query search
> >>>went down by factor that was almost linear with the number of
> >>>parallel processes running. the key to parallel processing is the
> >>>IPC and message passing can be simpler and cleaner than threads and
> >>>locks. also it is more scalable as the same architecture can be
> >>>spread to multiple boxes with no new coding and threads can't do
> >>>that at all.
> >>
> >>I don't really understand most of that, as I'm not familiar with
> >>this project the you're talking about. Speaky generically, you have
> >>two choices if you want to get useful work done while blocking on
> >> I/O 1) You use threading, or 2) You make the I/O handler part of
> >>the event loop.
> >>
> >>2) Is harder to get right,
> >
> > Isn't it nice that people have already written code with the I/O
> > handling built into the event loop?
>
> Yes, but people don't want to wait for you to integrate their blocking
> resource access with the event loop.
If some particular resource can *only* be accessed via blocking methods,
then you should stick it into another process -- then you access that
other process via RPC simulated with message passing.
> An advantage with threads is that you get decent scheduling for free,
> with zero effort.
Having blocking resources each in their own process *also* gets you
decent scheduling for free, with zero effort.
> You can disagree if you like, but the vast majority of the world is
> using threads for *some* reason.
Buzzword compliancy?
Threads have their place, but I'm not sure what that place is.
> >>However, I can't see how you avoid locking - with events you just
> >>force everything to be serialized, therefore you've lost any
> >>potential parallelism.
> >
> > Well, all serialized within the one process, but you can have
> > multiple processes, which you talk to through I/O.
>
> Yes, that's what I said. But the access to the resource *must* be
> serialized. Locking by any other name ...
Locking is a form of serialization.
Serialization is not a form of locking.
Uri believes, and I believe, that having serlization done by doing all
the "need to be serliazed" operations in one process is less prone to
error. You believe that doing serliazation by acquiring and releasing
explicit locks on the resources is better.
> >>I respectfully question this "real parallel scalability" assertion.
> >>I think you're being just a teensy bit zealot-ish here.
> >
> > He's the president of "Stem Systems", whose main product, stem, is a
> > message passing system. What would you expect?
>
> <blows top>
> That does it.
>
> I don't go researching everyone who replies ... and frankly I'll
> definitely check next time to see if I'm replying to a marketing droid
> with a hidden agenda.
No, he's not a 'marketing droid' -- he wrote much (all?) of stem. He
knows what he's talking about.
That's not to say he isn't biased, but then again, so are you.
> I asked a technical question about ithreads, and I got some reflexive
> offtopic nonsense about "switching" to a random message passing
> system.
>
> I clearly said I was building an ORB (ie infrastructure), that will
> help Perl play in the CORBA/J2EE space, so "switching" makes no god
> damned sense whatsoever.
I don't recall the beginning of this thread -- but if you've already
written your program with threads, then go ahead and use threads.
OTOH, if you *haven't* written your program -- I advise you to think
long and hard about whether a thread solution or an event-dispatch
solution will be faster, more stable, and less prone to error in the
long run.
> >>I'm sure I can do just as well with a threaded server, and you can't
> >>*really* avoid race conditions (and locking) unless you throw
> >>parallelism out.
> >
> > If you use multiprogramming instead of multithreading, any one
> > process is purely serial.
> >
> > One can avoid deadlocks due to recursion simply by changing RPC of
> > the form: "send request and wait for *my* response, and *only* my
> > response" into: "send message and wait for *any* messages,
> > dispatching those which are requests, until one of those messages is
> > my response"
>
> Yes, that's the "reactive" single threaded pattern. There's plenty
> written about it. It's beaut!
I thought you were slamming on all single-threaded patterns... this
sounds like quite a turn around!
> > Other forms of race conditions/deadlocks may still require work, but
> > you could create a centralized process which hands out locks, or
> > something like that.
>
> Yes. Locking. *Thank you*.
Of course, that's not the only way, nor necessarily the best way.
For some kinds of resources, it's far better to have serialization done
without explicit locks, by instead having all operations on that
resource done in one single process.
> >>I don't see how your model as described can really exploit multiple
> >>CPUs,
> >
> > Take those components which don't interact nicely into an event
> > dispatching model by themselves (DBI, for example), and put them
> > into their own processes (and talk to them via RPC/messages). The
> > OS will likely run those processes on the other CPUs.
>
> Sure, if you can afford all these processes, and the overhead of
> communications between them.
Communication is communication -- threads have to communicate with each
other, too, if they're being run on seperate processes.
And what happens if you want to run your threads on multiple *machines*,
instead of one machine within a CPU?
With multiple processes, you can just start the process on the other
machine, and talk to it with sockets.
With threads? Hmm, I suppose you could put a swapfile on a shared
filesystem, and have a special inter-machine process scheduler... but
this only works if all the machines have the exact same architecture and
shared libraries, and it has various other drawbacks besides... That's
not to say it can't be done (and indeed, it *has* been done, tho I don't
recall the name of the project), but I wouldn't use that design unless I
had to.
> >>without exchanging more messages between seperate processes,
> >
> > The way I see it, you send one message per request, and get one
> > message per response. Where do you see the extra messages?
>
> [So, there's a response now? I thought we didn't need those
> troublesome responses ...]
Who said that? *I* certainly never did.
> Who co-ordinates all this scheduling, and deciding who gets what
> message?
You send the message to the process which contains the resource which
you want access to.
> Unless it's random, or round-robin, there's going to be some
> overhead in determining who is most lightly loaded, I would have
> thought.
Hmm... assuming that you're talking about what to do if more than one
other process has access to the resource you need to manipulate (or if
the 'resource' is merely CPU time), then I guess that these are the
simplest ways of doing it.
Also, you could have every message (including responses) include a
"current load" message.
And you could send infrequent pings to those processes which haven't
sent you anything in a while, asking if they're alive and what their
"current load" is.
[snip stuff about corba and orbs and stuff, which I mostly don't know
about.]
> Now I'm going to play some computer games, and let the steam blow out
> of my ears for a bit!
Play XEvil! :) Get it from www.xevil.com, now! :)
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 07 Oct 2002 02:58:58 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: Kill current process(es)
Message-Id: <slrnaq1tte.qo8.garry@zfw.zvolve.net>
On Sat, 5 Oct 2002 01:06:25 -0500 (CDT), BUCK NAKED1
<dennis100@webtv.net> wrote:
> I've looked at the kill and signal docs and don't quite understand how
> to use them. If you want to make sure that all processes are killed in a
> perl script file, in case it hangs or the user backs out. Will this do
> it?
>
> END {
> kill -9 $_;
> }
>
From Randal Schwartz <8cpw0y2gb2.fsf_-_@gadget.cscaper.com> in
comp.unix.shell, about the useless use of kill -9 award:
No no no. Don't use kill -9.
It doesn't give the process a chance to cleanly:
1) shut down socket connections
2) clean up temp files
3) inform its children that it is going away
4) reset its terminal characteristics
and so on and so on and so on.
Generally, send 15, and wait a second or two, and if that doesn't
work, send 2, and if that doesn't work, send 1. If that doesn't,
REMOVE THE BINARY because the program is badly behaved!
Don't use kill -9. Don't bring out the combine harvester just to tidy
up the flower pot.
Just another Useless Use of Usenet,
By the way, how do you expect the END block to get control, if the
Perl script is hanging?
--
Garry Williams
------------------------------
Date: 6 Oct 2002 20:06:14 -0700
From: leemur@uclink4.berkeley.edu (Stanley Lee)
Subject: needleman-wunsch alignment
Message-Id: <65c70263.0210061906.6f6f3f8c@posting.google.com>
hi im very new to perl and i am trying to implement a needleman-wunsch
alignment of two protein sequences
(http://helix.biology.mcmaster.ca/721/outline2/node39.html)
to align the sequences, first you construct an initial matrix of 0s
and 1s, 1s appear wherever the sequences match (please see the URL)
and then you iterate through this matrix a second time and add the
largest value from the adjacent columns and rows. this part i have
trouble on, i can get the matrix with half of the values that i need,
but the other half is wrong. has anyone ever tried anything like this
before? heres some code that im using:
$seq1 = "AJCJNRCKCRBP";
$seq2 = "ABCNJRQCLCRPM";
$L1 = length($seq1);
$L2 = length($seq2);
@matrix = ();
for ($i = 0; $i < $L1; $i +=1){ #sets up the 1s and 0s matrix,
works fine
$aa1 = substr($seq1, $i, 1);
for ($k = 0; $k < $L2; $k +=1){
$aa2 = substr($seq2, $k, 1);
if ($aa1 eq $aa2){
$matrix[$i][$k] = 1;
print "$matrix[$i][$k]";
}else{
$matrix[$i][$k] = 0;
print "$matrix[$i][$k]";
}
}
print "\n";
}
print "\n";
for ($i = $L1-2; $i >= 0; $i -=1){ #modifies matrix
for ($k = $L2-2; $k >= 0; $k -=1){
$ii = $i + 1; #previous row
$kk = $k + 1; #previous col
$ct = 0;
for ($a = $kk; $a <= $L1; $a += 1){ #row same, col move
$list[$ct] = $matrix[$ii][$a];
@list = sort(@list);
@list = reverse(@list);
$max_row = $list[0];
$ct += 1;
}
@list = ();
$cnt = 0;
for ($a = $ii; $a <= $L2; $a += 1){ #col same, row move
$list[$cnt] = $matrix[$a][$kk];
@list = sort(@list);
@list = reverse(@list);
$max_col = $list[0];
$cnt += 1;
}
@big = sort($max_row, $max_col);
$maxm = $big[1];
$matrix[$i][$k] = $matrix[$i][$k] + $maxm;
#print "$matrix[$i][$k]";
}
print "\n";
}
011111111121
021111211112
113232222322
212333333333
323343333433
343334544444
334444456555
434444465666
545454456766
655555566677
666666666678
this is what im getting out.
anything would help.
thanks! stanley.
------------------------------
Date: Mon, 07 Oct 2002 00:13:30 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: needleman-wunsch alignment
Message-Id: <3DA109EA.31DBD4E2@earthlink.net>
Stanley Lee wrote:
>
> hi im very new to perl and i am trying to implement a needleman-wunsch
> alignment of two protein sequences
> (http://helix.biology.mcmaster.ca/721/outline2/node39.html)
> to align the sequences, first you construct an initial matrix of 0s
> and 1s, 1s appear wherever the sequences match (please see the URL)
> and then you iterate through this matrix a second time and add the
> largest value from the adjacent columns and rows. this part i have
> trouble on, i can get the matrix with half of the values that i need,
> but the other half is wrong. has anyone ever tried anything like this
> before? heres some code that im using:
I don't pretend to know anything about the problem you're solving, but I
can make some suggestions to make your code run faster.
> $seq1 = "AJCJNRCKCRBP";
> $seq2 = "ABCNJRQCLCRPM";
> $L1 = length($seq1);
> $L2 = length($seq2);
Because perl stores the length of a string as part of the string's
structure (rather than having "\0" terminated strings, where you need to
search for the "\0" every time you want to find the length), it's very
fast to find a string's length. So, it will be clearer, and not much
slower, to use length($seq1) in each of the places where you use $L1.
> @matrix = ();
Is that @matrix is a global variable? Bleh, don't do that.
Enable strictures, and declare the variable with my().
use strict;
my @matrix;
> for ($i = 0; $i < $L1; $i +=1){ #sets up the 1s and 0s matrix,
> works fine
> $aa1 = substr($seq1, $i, 1);
> for ($k = 0; $k < $L2; $k +=1){
> $aa2 = substr($seq2, $k, 1);
> if ($aa1 eq $aa2){
> $matrix[$i][$k] = 1;
> print "$matrix[$i][$k]";
> }else{
> $matrix[$i][$k] = 0;
> print "$matrix[$i][$k]";
> }
> }
> print "\n";
> }
> print "\n";
I would code this as:
my (%chars1, %chars2, $i);
$i = 0; push @{$chars1{$_}}, $i++ for split //, $seq1;
$i = 0; push @{$chars2{$_}}, $i++ for split //, $seq2;
while( my ($char, $indices) = each %chars1 ) {
my $indices2 = $chars2{$char} or next;
for my $m (@matrix[@$indices]) {
@{$m}[@$indices2] = (1) x @$indices2;
}
}
for $i ( 0 .. length($seq1)-1 ) {
my $row = ( $matrix[i] ||= [] );
print( $row->[$_] ||= 0 )
for 0 .. length($seq2)-1;
print "\n";
}
print "\n";
> for ($i = $L1-2; $i >= 0; $i -=1){ #modifies matrix
> for ($k = $L2-2; $k >= 0; $k -=1){
This is kind of loop is probably better written as:
for $i ( reverse 0 .. length($seq1)-1 ) {
for my $j ( reverse 0 .. length($seq2)-1 ) {
> $ii = $i + 1; #previous row
> $kk = $k + 1; #previous col
>
> $ct = 0;
> for ($a = $kk; $a <= $L1; $a += 1){ #row same, col move
> $list[$ct] = $matrix[$ii][$a];
> @list = sort(@list);
> @list = reverse(@list);
> $max_row = $list[0];
> $ct += 1;
> }
This could be better written as:
my $max_row = -1;
$_ > $max_row and $max_row = $_
for @{ $matrix[$ii] }[ $kk .. $L1-1 ];
> @list = ();
>
> $cnt = 0;
> for ($a = $ii; $a <= $L2; $a += 1){ #col same, row move
> $list[$cnt] = $matrix[$a][$kk];
> @list = sort(@list);
> @list = reverse(@list);
> $max_col = $list[0];
> $cnt += 1;
> }
my $max_col = -1;
$$_[$kk] > $max_col and $max_col = $$_[$kk]
for map @matrix[ $ii .. $L2-1 ];
> @big = sort($max_row, $max_col);
> $maxm = $big[1];
> $matrix[$i][$k] = $matrix[$i][$k] + $maxm;
$matrix[$i][$j] +=
($max_row > $max_col) ? $max_row : $max_col;
> #print "$matrix[$i][$k]";
> }
> print "\n";
> }
[snip]
> this is what im getting out.
Well, that's what your code does.
Explain what you *want* it to produce, and maybe we can help you.
PS: All code in this message is untested.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Mon, 07 Oct 2002 01:11:05 GMT
From: cp <cpryce@pryce.nospam.net>
Subject: Re: One line to Segfault Perl
Message-Id: <061020022016169206%cpryce@pryce.nospam.net>
In article <slrnapsadh.9oh.dha@panix2.panix.com>, David H. Adler
<dha@panix2.panix.com> wrote:
> In article <3D9DA959.1090005@thecouch.homeip.net>, Mina Naguib wrote:
> >
> >
> > Paul Gillingwater wrote:
> >> Here's a Perl script which segfaults Perl:
> >>
> >> #!/usr/bin/perl
> >> undef tcp;
> >
> >
> > Just for the record, I get the same thing:
> >
> > [mina@blackcorner] ~ $ perl -e 'undef anything;'
> > Segmentation fault
>
> It gets odd here.
>
> bash-2.05$ perl -v
>
> This is perl, v5.6.1 built for i386-freebsd
> [snip]
>
> bash-2.05$ perl -le 'undef tcp'
> bash-2.05$
>
> Nothing. *however*, if I put it in a file...
>
> bash-2.05$ cat doesitcore.pl
> #!/usr/bin/perl
> undef tcp;
>
> bash-2.05$ ./doesitcore.pl
> Segmentation fault (core dumped)
> bash-2.05$
>
>
> So... for me, on FreeBSD (4.6-STABLE), it does nothing as a one-liner,
> but core dumps as a script.
It does neither for my Solaris 8 box (perl 5.6.1 built with gcc):
$ perl -v
This is perl, v5.6.1 built for sun4-solaris
...
$ perl -le 'undef tcp;'
$
$ cat undef.pl
#!/usr/local/bin/perl
undef tcp;
$ perl undef.pl
$
--
cp
remove 'nospam' to reply
------------------------------
Date: 07 Oct 2002 03:00:05 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Sharing a program?
Message-Id: <anqtbl$s89@dispatch.concentric.net>
"Joe Creaney" <joec@annuna.com> wrote in message
news:3D9F97AD.30905@annuna.com...
> I am fairly new to perl and programming but I wrote a very simple
> adventure program is there any place I can share this program?
>
1. You just did.
2. CPAN (Comprehensive Perl Archive Network) has a scripts repository, but
there doesn't seem to be a specific sub-repository for games
(http://www.cpan.org/scripts/index.html).
------------------------------
Date: Mon, 07 Oct 2002 02:00:21 GMT
From: "Dc" <dcpope@sbcglobal.net>
Subject: Simple Win32 batch file gives errors
Message-Id: <VU5o9.49$0f3.22431853@newssvr11.news.prodigy.com>
Hi,
I'm trying to simplify testing and running Perl scripts in a Win32
environment. Problem is, if I try to run more than one script in a DOS
window I get a message "cannot find the path specified" and then the script
runs anyway.
If this part of the legacy DOS real-mode biz or do I need to include
something to clear memory so I can run consecutive scripts in the same DOS
window?
It sucks having to try to make this work in Windows but you play the cards
you're dealt.
Here's the script:
E:
cd Perl files
perl -w %1.pl
C:
TIA for any help anyone can offer.
David
------------------------------
Date: Mon, 7 Oct 2002 14:51:35 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Simple Win32 batch file gives errors
Message-Id: <sQ8o9.13$Le7.52564@vicpull1.telstra.net>
"Dc" <dcpope@sbcglobal.net> wrote in message
news:VU5o9.49$0f3.22431853@newssvr11.news.prodigy.com...
> Hi,
>
> I'm trying to simplify testing and running Perl scripts in a Win32
> environment. Problem is, if I try to run more than one script in a DOS
> window I get a message "cannot find the path specified" and then the
script
> runs anyway.
Because the path cant be found
> If this part of the legacy DOS real-mode biz or do I need to include
> something to clear memory so I can run consecutive scripts in the same DOS
> window?
>
> It sucks having to try to make this work in Windows but you play the cards
> you're dealt.
>
> Here's the script:
>
> E:
> cd Perl files
> perl -w %1.pl
> C:
the cd line is failing, probably because you are already in that directory.
try specifying an absolute path.
BTW this is an error with your batch file programming, not with Perl...
Wyzelli
--
$j='on the job';$h='hacker';$p='Perl';for(reverse(1..100)){
$s=($_!=1)?'s':'';$t=($_!=1)?'one of those':'that';
print"$_ $h$s of $p $j,\n$_ $h$s of $p.\nIf $t $h$s should code a bug,\n";
$_--;$s=($_==1)?'':'s';print"There'd be $_ $h$s of $p $j!\n\n";}print"*use
strict*";
------------------------------
Date: Sun, 6 Oct 2002 21:11:11 -0400
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: || versus OR
Message-Id: <gb5o9.24541$GF5.1628036@news4.srv.hcvlny.cv.net>
"Aaron Simmons" <asimmons@mitre.org> wrote in message
news:anicri$rr1$1@newslocal.mitre.org...
> Here's one that burned me bad once:
> ##############################
> #########
> # Test #1--$input_name defined
> #########
> $input_name = 'Bob';
>
> $name_t1 = $input_name || 'Aaron';
> $name_t1_2 = $input_name or 'Aaron';
>
> print "name_t1:$name_t1\n";
> print "name_t1_2:$name_t1_2\n";
>
> #########
> # Test #2--$input_name2 defined
> #########
>
> $name_t2 = $input_name2 || 'Aaron';
> $name_t2_2 = $input_name2 or 'Aaron';
>
> print "name_t2:$name_t2\n";
> print "name_t2_2:$name_t2_2\n";
> ##############################
>
> With test#2, $name_t2_2 does not get assigned 'Aaron'
>
> -Aaron
>
>
--snip--
Excellent example of precedence, but an equally good example of why we
should always use strict and warnings.
Bill
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 3927
***************************************