[16878] in Perl-Users-Digest
Perl-Users Digest, Issue: 4290 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 11 18:15:50 2000
Date: Mon, 11 Sep 2000 15:15:28 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968710528-v9-i4290@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 11 Sep 2000 Volume: 9 Number: 4290
Today's topics:
Re: Recognizing wrapped lines <bkennedy@hmsonline.com>
Re: Reference to a Function!! nobull@mail.com
Re: Reference to a Function!! houseofpain@my-deja.com
Re: Regexp Question (corrected weird line break ) <mischief@motion.net>
Re: Regexp Question <mischief@motion.net>
Re: s/// mystery: regexp challenge <ruedas@geophysik.uni-frankfurt.de>
Re: s/// mystery: regexp challenge (Abigail)
Sorting ABC..123 instead of 123..ABC <oe1emn@chello.at>
Re: Sorting ABC..123 instead of 123..ABC (Mark-Jason Dominus)
Re: Sorting ABC..123 instead of 123..ABC <ren.maddox@tivoli.com>
Re: Sorting ABC..123 instead of 123..ABC <stephenk@cc.gatech.edu>
Re: starting new processes <tim@ipac.caltech.edu>
Re: strip carriage returns error nobull@mail.com
Re: This *should* be easy, string parsing question (Andrew J. Perrin)
Re: This *should* be easy, string parsing question (Craig Berry)
Re: This *should* be easy, string parsing question (Craig Berry)
Re: This *should* be easy, string parsing question <spragg@cs.ucdavis.edu>
Re: This *should* be easy, string parsing question <ren.maddox@tivoli.com>
Re: This *should* be easy, string parsing question (Craig Berry)
Re: uninitialized value - but I have initilised it! Hav <tim@ipac.caltech.edu>
Unix ps and perl question <pbarone@harris.com>
Re: Unix ps and perl question (Abigail)
Re: use strict: why? cfedde@sl3d.com
Re: using filehandles in strict mode nobull@mail.com
Re: using filehandles in strict mode (Tom Christiansen)
Re: using filehandles in strict mode <bkennedy@hmsonline.com>
Re: Variable not accepting value <lr@hpl.hp.com>
Re: xml type file parsing help. <jaap@stack.nl>
Re: xml type file parsing help. <rickyfusion@nospamfusionserver.com>
Re: zap dupes, preserve order <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Sep 2000 20:27:03 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Recognizing wrapped lines
Message-Id: <rebv5.21076$AW2.262003@news1.rdc2.pa.home.com>
<awr@cpu.com> wrote in message news:8pba86$8tk$1@nnrp1.deja.com...
> In files I'm processing, some lines are data of interest, some are not.
> To complicate matters, the data lines may be wrapped. It is pretty
> straightforward to build a regular expression to recognize the whole
> data lines. Is there a straightforward way to recognize the data when it
> is spread across multilple lines, especially since I don't know where in
> the record it may get wrapped?
If you can form a regular expression to match a whole line of data, you can
use the 's' and 'g' modifiers for regexps - the first lets . match a newline
character, the second allows for repeated matches -
while($yourdata =~ /($yourpattern)/g) { # scans for your pattern
my $data = $1;
$data =~ s/[\r\n]//g; # remove embedded newline and carriage return
characters
print "I found $data\n";
}
See 'perldoc perlre'. If the file is too large to fit in one scalar,
perhaps you can scan groups of lines and do something similar.
--Ben Kennedy
------------------------------
Date: 11 Sep 2000 18:55:32 +0100
From: nobull@mail.com
Subject: Re: Reference to a Function!!
Message-Id: <u9bsxubyp7.fsf@wcl-l.bham.ac.uk>
houseofpain@my-deja.com writes:
> How do a store a reference to a function in oop.
FAQ: "How can I pass/return a {Function, FileHandle, Array, Hash,
Method, Regexp}?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 11 Sep 2000 18:19:32 GMT
From: houseofpain@my-deja.com
Subject: Re: Reference to a Function!!
Message-Id: <8pj7mq$uh6$1@nnrp1.deja.com>
In article <m1aedevpij.fsf@halfdome.holdit.com>,
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "houseofpain" == houseofpain <houseofpain@my-deja.com> writes:
>
> houseofpain> How do a store a reference to a function in oop.
> houseofpain> $function = \&foo works but what if the function is
> houseofpain> $this->foo() how do i store that in a var.
>
> my $function = sub { $this->foo(@_) };
>
> :-)
>
> Just be sure that $this is a lexical variable, and doesn't get changed
> by the time you need to call it.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
>
Thanks, that was the answer i was looking for.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Sep 2000 16:55:43 -0500
From: "Chris Stith" <mischief@motion.net>
Subject: Re: Regexp Question (corrected weird line break )
Message-Id: <srql49rfct620@corp.supernews.com>
<cghawthorne@yahoo.com> wrote in message news:8o769c$4c4$1@nnrp1.deja.com...
> Hi!
Hullo.
> I have a question on constructing a regexp. I'm designing a CGI script
> that will need to take an image file name
> (/home/person/public_html/img.gif)
> and translate it to something that can be used in an <img> tag
> (example.com/~person/img.gif). The easiest way I can think of to do
> this is to use a regexp to return everything from the last "/" on and
> deal with it from there.
$fully_qualified_filename =~
s/\/home\/([\w.]+)\/public_html\/([\w.]+)/example.com\/~$1\/$2/;
### Cargo cult programming... Mmm mmm good!
> Any ideas would be appreciated!
I think I'll have steak for dinner tonight. I also think I'll have
some brussels sprouts with that steak. And maybe a beer or
three. Thanks for appreciating my random thoughts!
Chris Stith
mischief@pikenet.net mischief@motion.net mischief@bachelorboy.com
mr_mischief1@hotmail.com _pcu_@yahoo.com chris.stith-personal@nemonet.com
There's no time like one remembered fondly.
>
>
>
------------------------------
Date: Mon, 11 Sep 2000 16:44:35 -0500
From: "Chris Stith" <mischief@motion.net>
Subject: Re: Regexp Question
Message-Id: <srqkfeh7ct6161@corp.supernews.com>
<cghawthorne@yahoo.com> wrote in message news:8o769c$4c4$1@nnrp1.deja.com...
> Hi!
Hullo.
> I have a question on constructing a regexp. I'm designing a CGI script
> that will need to take an image file name
> (/home/person/public_html/img.gif)
> and translate it to something that can be used in an <img> tag
> (example.com/~person/img.gif). The easiest way I can think of to do
> this is to use a regexp to return everything from the last "/" on and
> deal with it from there.
$fully_qualified_filename =~
s/\/home\/([\w.]+)\/public_html\/([\w.]+)/example.com\/~$1\/$2/;
### Cargo cult programming... Mmm mmm good!
> Any ideas would be appreciated!
I think I'll have steak for dinner tonight. I also think I'll have
some brussels sprouts with that steak. And maybe a beer or
three. Thanks for appreciating my random thoughts!
Chris Stith
mischief@pikenet.net mischief@motion.net mischief@bachelorboy.com
mr_mischief1@hotmail.com _pcu_@yahoo.com chris.stith-personal@nemonet.com
There's no time like one remembered fondly.
------------------------------
Date: Mon, 11 Sep 2000 20:05:02 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: Re: s/// mystery: regexp challenge
Message-Id: <39BD1ECE.8DDAA919@geophysik.uni-frankfurt.de>
Thanks a lot to Kai and Abigail, that works perfectly.
Abigail wrote:
>>"" use Tie::IxHash;
>What is the purpose of the tie here?
In this context actually none, but in the original converter order
matters, because e.g. \& was another command, which has to be converted
into & if it is not converted first, all of the rest will be messed
up. Admittedly, I could have removed the tie for the test file.
--
------------------------------------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics, J.W.Goethe University Frankfurt
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
------------------------------------------------------------------------
------------------------------
Date: 11 Sep 2000 18:40:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: s/// mystery: regexp challenge
Message-Id: <slrn8rq9m5.pg4.abigail@alexandra.foad.org>
Thomas Ruedas (ruedas@geophysik.uni-frankfurt.de) wrote on MMDLXVIII
September MCMXCIII in <URL:news:39BD1ECE.8DDAA919@geophysik.uni-frankfurt.de>:
:} Thanks a lot to Kai and Abigail, that works perfectly.
:}
:} Abigail wrote:
:} >>"" use Tie::IxHash;
:} >What is the purpose of the tie here?
:} In this context actually none, but in the original converter order
:} matters, because e.g. \& was another command, which has to be converted
:} into & if it is not converted first, all of the rest will be messed
:} up. Admittedly, I could have removed the tie for the test file.
So, why use a hash? If order matters, why not just use an array?
Abigail
--
perl -we '$| = 1; $_ = "Just another Perl Hacker\n"; print
substr $_ => 0, 1 => "" while $_ && sleep 1 => 1'
------------------------------
Date: Mon, 11 Sep 2000 18:53:14 GMT
From: "Manfred Eitenberger" <oe1emn@chello.at>
Subject: Sorting ABC..123 instead of 123..ABC
Message-Id: <uS9v5.459$Pt2.12071@news.chello.at>
This might be an easy one.
How do I sort to get letters before figures ?
Sort order:
ABC...Z123..9
instead of
123..9ABC..Z
------------------------------
Date: Mon, 11 Sep 2000 19:25:50 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Sorting ABC..123 instead of 123..ABC
Message-Id: <39bd31bd.ba9$200@news.op.net>
In article <uS9v5.459$Pt2.12071@news.chello.at>,
Manfred Eitenberger <oe1emn@chello.at> wrote:
>How do I sort to get letters before figures ?
Here's one possibility:
sub letters_first {
(my $aa = $a) =~ tr/0-9/\200-\211/;
(my $bb = $b) =~ tr/0-9/\200-\211/;
$aa cmp $bb;
}
@sorted = sort letters_first @whatever;
------------------------------
Date: 11 Sep 2000 14:37:36 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Sorting ABC..123 instead of 123..ABC
Message-Id: <m3ya0y1zzz.fsf@dhcp11-177.support.tivoli.com>
"Manfred Eitenberger" <oe1emn@chello.at> writes:
> This might be an easy one.
>
> How do I sort to get letters before figures ?
>
> Sort order:
>
> ABC...Z123..9
> instead of
> 123..9ABC..Z
Well, to get exactly that is pretty difficult, assuming you mean you
want a character-by-character comparison that uses that order instead
of the normal order.
However, if what you *really* want is simply to have strings starting
with digits to come after other strings, use:
print sort { $a <=> $b or $a cmp $b } <DATA>;
Since any string that does not begin with a digit will evaluate to 0
for the numerical compare, they will come before any string beginning
with a digit, and then they will be sorted as normal. (Though strings
beginning with 0 break this.)
Note that with this comparison, any strings starting with digits will
be sorted numerically, which may not be what you want. You can get
around that with something like:
print sort { $a =~ /^\D/ and $b =~ /^\d/ and -1 or
$a =~ /^\d/ and $b =~ /^\D/ or
$a cmp $b
} <DATA>;
This may be closer to what you really want, but it still does nothing
for internal digits (so 1A and AA still sort after 11 and A1,
respectively -- that is, the final order is A1, AA, 11, 1A). If you
want digits at every position to be sorted after letters at that
position, then that is the "pretty difficult" thing that I mentioned
at the beginning. Off-hand, I'm not even sure how to do it (unless
you can define a specific locale for it, which is not something with
which I'm familiar).
And if none of this is what you want, please post some examples of how
particular strings should sort. Here is a good batch to work with:
__DATA__
This is just a string.
This 2nd string has a number.
This 29 character string isn't.
123
78
19 plus some text
012
0
0 and some text
With this data, my first sort produces (note the problem with 0):
0
0 and some text
This 29 character string isn't.
This 2nd string has a number.
This is just a string.
012
19 plus some text
78
123
and my second produces:
This 29 character string isn't.
This 2nd string has a number.
This is just a string.
0
0 and some text
012
123
19 plus some text
78
Neither handles the "29" vs "2nd" "correctly". And as I stated, the
first sorts strings beginning with digits numerically while the second
sorts them as strings.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Mon, 11 Sep 2000 16:19:06 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Sorting ABC..123 instead of 123..ABC
Message-Id: <39BD3E38.8E2904FE@cc.gatech.edu>
Manfred Eitenberger wrote:
> This might be an easy one.
>
> How do I sort to get letters before figures ?
>
> Sort order:
>
> ABC...Z123..9
> instead of
> 123..9ABC..Z
I can think of 2 (relatively) simple ways of doing this, depending on
how you want to sort numbers.
If you want to compare as numbers (2<12):
@sorted = sort {$a <=> $b|| $a cmp$b} @unsorted;
If you want to compare as strings ('2'>'12'):
@sorted = sort {($a=~/^\d/)==($b=~/^\d/)?($a cmp $b):($b cmp $a)}
@unsorted;
perldoc -f sort
perldoc -q sort
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Mon, 11 Sep 2000 12:35:38 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: starting new processes
Message-Id: <39BD340A.1E9E1F61@ipac.caltech.edu>
Harri Havanka wrote:
> I have to start new process, if their count is <5.
> How I check this? I want only check count of
> mysubprocess.pl, not all processes.
> Fork-function seems little
> bit weird for me..
Start by reading perlipc and perlfaq8. Then ...
Why not count them as you start them?
(Untested.)
my ($nproc,$maxproc) = (0,5);
for(;;) {
if($nproc >= $maxproc) {
wait;
--$nproc;
} elsif(defined (my $pid=fork)) {
if($pid) { print "Spawned child $pid\n"; ++$nproc; } # Parent
else { exec "whatever","my","args"; } # Child
} else {
die "Bad fork; $!";
}
--$nproc while waitpid(-1,WNOHANG) > 0;
}
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: 11 Sep 2000 19:11:19 +0100
From: nobull@mail.com
Subject: Re: strip carriage returns error
Message-Id: <u98zsybxyw.fsf@wcl-l.bham.ac.uk>
Pierre Rodrigues <pirod@webdifusao.com> writes:
> sometimes I get the following error:
> "Software error:
> (Maybe you didn't strip carriage returns after a network transfer?) "
>
> I tested the same script on 2 servers and only got this message in one.
> What sort of error causes this message?
I'd guess any sort.
This is probably fixed text that your web admin has put on the error
page because he was tired of answering queries from users who had
fogotten to upload in text mode.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 11 Sep 2000 14:15:25 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: This *should* be easy, string parsing question
Message-Id: <u3dj6pzgi.fsf@demog.berkeley.edu>
cyberlurker@my-deja.com writes:
> $buffer = "item0=value1&item2=value2";
>
> @pairs = split(/\&/,$buffer);
Useless use of backslash:
@pairs = split(/&/,$buffer);
> foreach $pair (@pairs)
> {
> ($a,$b)=split(/=/,$pair);
> $FORM{$a} = $b;
Dangerous to use system variables $a and $b (perldoc -f sort). Use
something else.
> }
>
> now u have a hash %FORM, in which the "itemname" is the key
> and the "itemvalue" is the value...
>
> from the Matt's script archive -- long before cgi.pm
>
Be afraid. Be very afraid. :()
--
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------
------------------------------
Date: Mon, 11 Sep 2000 19:50:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: This *should* be easy, string parsing question
Message-Id: <srqdrdk0ct6141@corp.supernews.com>
drstone@my-deja.com wrote:
: I have a script that does some stuff and then returns me a long
: string of name value pairs....
: something along the lines of:
: item=value&item2=value2&item3=value3....
This looks like a CGI GET string; if it is, I strongly recommend using
CGI.pm to access the parameters, rather than rolling your own code. It
does this properly, including such things as translating encoded
characters and the like, and transparently handling POSTed data as well.
If this is not a CGI question, read on.
: so, I need to parse this and retrieve the
: name value pairs.
:
: Any thoughts on a quick and dirty way to extract using the
: & and the = as my conditions?
Assuming that there is not special encoding going on, and that & and =
appear only as separators:
$incoming = 'item=value&item2=value2&item3=value3';
%data = split /[&=]/, $incoming;
print "item2 = $data{item2}\n" # (for example)
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: Mon, 11 Sep 2000 19:53:02 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: This *should* be easy, string parsing question
Message-Id: <srqe0ui2ct6154@corp.supernews.com>
cyberlurker@my-deja.com wrote:
: $buffer = "item0=value1&item2=value2";
:
: @pairs = split(/\&/,$buffer);
No need to escape that &.
: foreach $pair (@pairs)
: {
: ($a,$b)=split(/=/,$pair);
: $FORM{$a} = $b;
: }
:
: now u have a hash %FORM, in which the "itemname" is the key
: and the "itemvalue" is the value...
:
: from the Matt's script archive -- long before cgi.pm
But note that this does not handle encoded values, which might be
encountered if this is being used for CGI purposes. Note also that Matt's
code for this is broken in many places, too. If you're parsing CGI
parameters, CGI.pm is the safe choice.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: 11 Sep 2000 19:58:40 GMT
From: Adam Trace Spragg <spragg@cs.ucdavis.edu>
Subject: Re: This *should* be easy, string parsing question
Message-Id: <8pjdhg$525$1@mark.ucdavis.edu>
Peter J Scott <peter@psdt.com> wrote:
: %value = /([^=]+)=([^&]+)(?:&|$)/g;
Would someone mind please adding a little English to this? I'm trying to
learn regexps as best I can, and this one eludes me.
I realize that if you are good with regular expressions, it's easy to look
up in the docs about how this works, but it's not always easy to go in the
other direction.
Thanks!
Adam
------------------------------
Date: 11 Sep 2000 14:07:57 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: This *should* be easy, string parsing question
Message-Id: <m31yyq3fxu.fsf@dhcp11-177.support.tivoli.com>
drstone@my-deja.com writes:
> item=value&item2=value2&item3=value3....
>
> so, I need to parse this and retrieve the
> name value pairs.
#!/usr/local/bin/perl -w
use strict;
$_ = "item=value&item2=value2&item3=value3";
my %items = split /[=&]/;
print "$_:$items{$_}\n" for sort keys %items;
__END__
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Mon, 11 Sep 2000 21:15:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: This *should* be easy, string parsing question
Message-Id: <srqirguhct635@corp.supernews.com>
Adam Trace Spragg (spragg@cs.ucdavis.edu) wrote:
: Peter J Scott <peter@psdt.com> wrote:
: : %value = /([^=]+)=([^&]+)(?:&|$)/g;
:
: Would someone mind please adding a little English to this? I'm trying to
: learn regexps as best I can, and this one eludes me.
First, it's not how I'd do it. I would use the split trick I posted, and
if I had to do it as a regex, it would look like this:
%value = /(.*?)=(.*?)(?:&|$)/g;
Let's discuss both versions.
Translated into English (with a little sloppiness), the first regex above
reads "Match and save a string of non-'=' characters, then match a '=',
then match and save a string of non-"&" characters, and finally match an &
or the end of the string". The /g makes this match happen over and over,
as many times as possible. The two saved matches result in a list of
matched keys and values accumulating, which is the format of a hash
initializer.
The final portion of the match consumes the trailing '&' character, if
any, so that the next match begins just past it.
My version uses non-greedy matching, matching and saving any characters up
to but not including the first '=', then matching that '=', then matching
and saving any characters up to but not including the next '&' or
end-of-line. The behavior is almost identical (leaving aside cases
involving e.g. embedded newlines), but I think expressing it using
non-greedy matching is more direct.
: I realize that if you are good with regular expressions, it's easy to look
: up in the docs about how this works, but it's not always easy to go in the
: other direction.
If you yearn to become a regex guru, I highly recommend Friedl's
_Mastering Regular Expressions_.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Every force evolves a form."
| - Shriekback
------------------------------
Date: Mon, 11 Sep 2000 11:27:43 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: uninitialized value - but I have initilised it! Haven't I?
Message-Id: <39BD241F.A510CFC2@ipac.caltech.edu>
Mark Worsdall wrote:
>
> In article <39B5AAF2.E36E7235@ipac.caltech.edu>, Tim Conrow
> <tim@ipac.caltech.edu> writes
> >perldoc -f defined
> >
>
> read that.
>
> So do this instead?
>
> my $name = '';
> my $value = '';
> my $pair = '';
> my @pairs = ();
> my $buffer = '';
>
> if ($ENV{'REQUEST_METHOD'} eq 'GET') {
> # Split the name-value pairs
> if defined $ENV{'QUERY_STRING'} {
> @pairs = split(/&/, $ENV{'QUERY_STRING'});
> }
> }
> elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
> # Get the input
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> # Split the name-value pairs
> @pairs = split(/&/, $buffer);
> }
> else {
> exit;
> }
You're still working too hard and still not guarding against the possibility
that $ENV{'REQUEST_METHOD'} won't be defined.
die "REQUEST_METHOD not defined.\n"
unless defined $ENV{'REQUEST_METHOD'};
my ($name,$value,$pair,@pairs,$buffer);
etc. etc. etc.
But anyway, use CGI.pm and save yourself the hassle.
--
-- Tim Conrow tim@ipac.caltech.edu |
------------------------------
Date: Mon, 11 Sep 2000 14:08:18 -0400
From: Phil Barone <pbarone@harris.com>
Subject: Unix ps and perl question
Message-Id: <39BD1F92.BA609A5B@harris.com>
I have a need to monitor a particular unix process to see if it exists.
Normally I would issue a ps and test the return string for the
particular process.
As implemented the Args portion of the command can be longer than my
Solaris ps output gives in response to the ps command. It looks like 75
or so chars.
Is there a way/method to get the entire process command/args?
--
Phil Barone (e-mail: pbarone@harris.com)
------------------------------
Date: 11 Sep 2000 18:43:29 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Unix ps and perl question
Message-Id: <slrn8rq9sj.pg4.abigail@alexandra.foad.org>
Phil Barone (pbarone@harris.com) wrote on MMDLXVIII September MCMXCIII in
<URL:news:39BD1F92.BA609A5B@harris.com>:
)) I have a need to monitor a particular unix process to see if it exists.
))
)) Normally I would issue a ps and test the return string for the
)) particular process.
))
)) As implemented the Args portion of the command can be longer than my
)) Solaris ps output gives in response to the ps command. It looks like 75
)) or so chars.
))
)) Is there a way/method to get the entire process command/args?
Perhaps, but that would be a Solaris specific question, and hence, is off
topic here, as the working of ps on Solaris has as much to do with Perl
as the sex life of woodpeckers.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: Mon, 11 Sep 2000 18:10:28 GMT
From: cfedde@sl3d.com
Subject: Re: use strict: why?
Message-Id: <oe9v5.84$W3.170860032@news.frii.net>
In article <39BC9C80.17FFADCE@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>
>Your thoughts make as much sense as feathers on a snake.
>
Surely Godzilla is familiar with Quetzalcoatl?
Perhaps the great mudpuppy has never traveled west of the Izu Islands.
--
This space intentionally left blank
------------------------------
Date: 11 Sep 2000 19:23:29 +0100
From: nobull@mail.com
Subject: Re: using filehandles in strict mode
Message-Id: <u97l8ibxem.fsf@wcl-l.bham.ac.uk>
mgopi@csa.iisc.ernet.in writes:
> i've declared use strict.
good.
> then whenever i use filehandles in a function such as fileno(),or
> assign it to something an error is shown as bare file handles caanot
> be used in strict mode.
Can you show us actual code that reproduces the error with fileno() please?
fileno(STDIN) works fine for me.
> i couldn't understand what does that mean.
If you are not confortable writing in English then it is even _more_
reason to _show_ us Perl code rather than try to describe your Perl
code using English.
I'm guessing you mean you've got something like:
my $fh = STDIN;
You need to change that to:
my $fh = \*STDIN;
or
my $fh = *STDIN{IO};
> another q on select.
Please do not post unrelated questions in one article.
> select returns the position of the filehandle in the bit or the filehandle
> itself
Which "select" are you talking about? The single paramter select
function? The 4-parameter select function? The IO::Select module?
AFAIK they each work as described in the relvant documentation.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 11 Sep 2000 13:01:52 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: using filehandles in strict mode
Message-Id: <39bd2c20@cs.colorado.edu>
In article <u97l8ibxem.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:
>I'm guessing you mean you've got something like:
>
>my $fh = STDIN;
>
>You need to change that to:
>
>my $fh = \*STDIN;
or simply:
my $fh = *STDIN;
>
>or
>
>my $fh = *STDIN{IO};
That one is unlikely. The *WHATEVER{PIECE} notation is not always
as useful as people wish it were. I would avoid it for non-internals
work unless you're into pain or wizardry, because it's not much fun
explaining the subtleties of globular autovivification and the lack
thereof.
--tom
------------------------------
Date: Mon, 11 Sep 2000 19:42:00 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: using filehandles in strict mode
Message-Id: <cAav5.21055$AW2.261369@news1.rdc2.pa.home.com>
<mgopi@csa.iisc.ernet.in> wrote in message
news:8pis7p$3ss$1@news.netmar.com...
> i've declared use strict.
> then whenever i use filehandles in a function such as fileno(),or assign
it to
> something
> an error is shown as
> bare file handles caanot be used in strict mode.
> i couldn't understand what does that mean.
> as far as i know i can't declare it using my function.
you should post an example of this
> another q on select.
> select returns the position of the filehandle in the bit or the filehandle
> itself
> thanx
The four argument select just returns the number of ready descriptors and
the amount and time until the loop would have timed out (or undef if you
specified undef as the timeout val). The arguments provided are modified
in-place to provide the information as to which descriptors are ready. This
is why all examples of select have something like $rout = $rin as arguments,
since the original bit information in $rin is preserved and the value of
$rout is used by select and consequently modified (clobbered). You check
$rout by using vec() again:
use strict;
use warnings;
my($rin,$rout,$data);
$rin = '';
vec($rin, fileno(STDIN), 1) = 1;
select($rout = $rin,undef,undef,undef); # $rin is your bit vector, wait
forever
if (vec($rout,fileno(STDIN),1)) { # is this bit in my returned bit vector
on?
print "STDIN is in my read array, better read from it now!\n";
$data = <STDIN>;
print "I read $data";
}
the IO::Select module is much easier interface to use that hides all the
file descriptors and bit vectors, perldoc IO::Select
--Ben Kennedy
------------------------------
Date: Mon, 11 Sep 2000 11:10:43 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Variable not accepting value
Message-Id: <MPG.1426bffa6868c50998ad50@nntp.hpl.hp.com>
In article <x7aedhinjl.fsf@home.sysarch.com> on Sat, 09 Sep 2000
15:37:51 GMT, Uri Guttman <uri@sysarch.com> says...
...
> another way would be to simply pop the last element before doin a normal
> looking loop.
Or simply --$#array_name;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Sep 2000 19:18:54 GMT
From: "Jaap" <jaap@stack.nl>
Subject: Re: xml type file parsing help.
Message-Id: <yeav5.191643$LX4.1610173@nlnews00.chello.com>
What's the problem?
Read the file and regexp the data you need out of it.
Be more specific if you still have questions.
------------------------------
Date: Mon, 11 Sep 2000 16:14:31 -0400
From: "Ric Smith" <rickyfusion@nospamfusionserver.com>
Subject: Re: xml type file parsing help.
Message-Id: <8pjehs$eic$1@server.cntfl.com>
Sorry, I should've been more specific.
I'm beginning with Reg Ex's and I need to assign the value between <chapnum>
and </chapnum> in the following to a var named $chapnum.
<chapnum>CHAPTER 798</chapnum>
Would this work?
$chapnum=~ s/<[\]chapnum>//;
but sometimes the tags are on different lines like this:
<sectbody>Whoever lives in an open state of adultery shall be
guilty of a misdemeanor of the second degree, punishable as
provided in s. 775.082 or s. 775.083. Where either of the parties
living in an open state of adultery is married, both parties so
living shall be deemed to be guilty of the offense provided for in
this section.</sectbody>
If someone could point me in the right direction hopefully with a little bit
of code.
Thanks.
--
Ric Smith
"Jaap" <jaap@stack.nl> wrote in message
news:yeav5.191643$LX4.1610173@nlnews00.chello.com...
> What's the problem?
> Read the file and regexp the data you need out of it.
> Be more specific if you still have questions.
>
>
------------------------------
Date: Mon, 11 Sep 2000 12:56:50 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: zap dupes, preserve order
Message-Id: <MPG.1426d8dc909f4b5b98ad53@nntp.hpl.hp.com>
In article <NDBu5.1384$Ne7.310126@news.uswest.net> on Sat, 9 Sep 2000
18:40:10 -0700, Christopher M. Jones <christopher_j@uswest.net> says...
[Rewritten on several lines so one can comment on the goings-on.]
> %arr=();
> @arr{@arr} = (0..@arr);
Should be 0 .. $#arr, but no matter.
> @arr{values %arr} = (keys %arr);
Now the serial numbers are also keys in the hash, as well as the values
in @arr?!
> foreach (sort keys %arr) { push @arr, $arr{$_}; }
Now a whole lot of stuff, sorted lexicographically instead of
numerically, gets appended to the contents of the original array @arr.
I'm sure you had something rational in mind, but this isn't it, and you
surely can't post a test that does what you want.
Rather than fix it, though, use the one-liner grep solution already
posted.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4290
**************************************