[13525] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 935 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 28 19:33:01 1999

Date: Tue, 28 Sep 1999 16:10:14 -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: <938560214-v9-i935@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Sep 1999     Volume: 9 Number: 935

Today's topics:
    Re: LOST NEWBIE <makkulka@cisco.com>
    Re: LOST NEWBIE (Larry Rosler)
        Matching problem with brackets <jpd@drum.terranet.com>
    Re: New book: Automating Windows With Perl (Randal L. Schwartz)
    Re: Perl Question (Mathew A. Hennessy)
    Re: Perl Question (Larry Rosler)
    Re: Perl Question <dheera@usa.net>
    Re: Perl Question <stampes@xilinx.com>
        reconnecting a closed pipe <msfrost@celluloidnexus.com>
    Re: Slice in scalar context (Randal L. Schwartz)
    Re: Sorting weird numeric data <uri@sysarch.com>
        Thread::Signal troubles (Jeff Magnusson)
        updated AcctInfo module (NewUser, DelUser) (Mathew A. Hennessy)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 28 Sep 1999 14:24:00 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: LOST NEWBIE
Message-Id: <37F131F0.1F6AC79D@cisco.com>

[ Jerry Preston wrote:

> I need to get by current working dir, cd to another dir, read the dir, find
> the latest file, the file will not have an ext or it will be 0..999. Then read
> the file.  Any ideas would be appreciated.

perldoc   Cwd
perldoc -f chdir
perldoc -f readdir

To find files in a dir and then sort them as per inode change times .
--
opendir(DIR, ".") || die "can't opendir" ;
@files  = sort { -C  $a <=> -C $b  } grep {  -f $_} readdir(DIR);
closedir DIR;
print "files in order of their inode change  times ",   join " ", @files ;
print "latest file  is ", $files [0] , "\n" ;
--



------------------------------

Date: Tue, 28 Sep 1999 15:08:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: LOST NEWBIE
Message-Id: <MPG.125adc24c7647a60989ff4@nntp.hpl.hp.com>

In article <37F131F0.1F6AC79D@cisco.com> on Tue, 28 Sep 1999 14:24:00 -
0700, Makarand Kulkarni <makkulka@cisco.com> says...

 ...

> To find files in a dir and then sort them as per inode change times .
> --
> opendir(DIR, ".") || die "can't opendir" ;
> @files  = sort { -C  $a <=> -C $b  } grep {  -f $_} readdir(DIR);

Don't try this on a large directory, say 1000 files or more, without 
being prepared to go out for a cup of coffee while it churns away stat-
ting each of those files far too many times.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Tue, 28 Sep 1999 19:05:28 -0400
From: Jim Drummey <jpd@drum.terranet.com>
Subject: Matching problem with brackets
Message-Id: <37F149B8.3F4F@drum.terranet.com>

I'm trying to find lines in a Samba config file by passing a parameter
containing a share name.

The lines begin with a square bracket followed by the share name and
ending with a square bracket like so:
[sharename]

I've tried several combos including:
if ( /^\[$sharename/ )   doesn't work
if ( $_ =~ $sharename && /^\[/ )  each of these conditions works by
                                  itself, but not when separated by
                                  the && operator 

If I leave one condition out, the statement works. I need to test
both conditions, that is 1) square brackets begin line and 2) followed
by $sharename.

I've looked at sample programs which appear to be doing what I'm
doing.

Any help would be appreciated.

Thanks
Jim Drummey
Drum Engineering Inc.
jpd@drum.terranet.com


------------------------------

Date: 28 Sep 1999 15:33:15 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: New book: Automating Windows With Perl
Message-Id: <m1g0zyd5uc.fsf@halfdome.holdit.com>

>>>>> "Kragen" == Kragen Sitaker <kragen@dnaco.net> writes:

Kragen> - the author claims Randal reviewed a draft of the book, which is an excellent
Kragen>   sign, but he misspells Randal's name :)

I did in fact review a draft of the book, with a huge disclaimer that
I dunno Windoze, so I was reviewing only the Perl-ish parts.

What I recall from the draft (for which I didn't get a chance to
rereview after my comments were taken) was that there was a lot of
beginning to intermediate-level Perl code.  Nothing terribly fancy or
leading edge, but it'll certainly be cleaner than the equivalent VB
stuff.  I probably could have rewritten every program in about 1/3 of
the lines, but that's, uh, just me. :)

I do recall some scary/dangerous Perl code, but if the author took my
comments to heart, I'm sure those'll have been eliminated.  I also
tried to point out the non-idiomatic code, but with much less fervor.

In general, the author looked like he had at least made *working*
code, if not robust code, and did cover a lot of those things that
make working with Windows nearly impossible.  After reading his
description of the OLE/COM/whatever-alphabet-soup evolution, let me
say that I am *happy* to not be a Windoze hacker.  How do you guys
ever put up with that nonsense?  Yeah, use Perl, and be somewhat sane,
I know. :)

print "Just another Perl (but not windoze) hacker," =~ /(.*)\(.*\) (.*)/

-- 
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!


------------------------------

Date: Tue, 28 Sep 1999 21:42:15 GMT
From: hennessy@cloud9.net (Mathew A. Hennessy)
Subject: Re: Perl Question
Message-Id: <rv2dhnod3i582@corp.supernews.com>

In article <7sr9mv$p7h$1@nnrp1.deja.com>,  <rthomp41@ford.com> wrote:
>Hello - I have a perl question for  comp.lang.perl newsgroup.

	I forget: is there a comp.lang.perl.questions ng?  I'm in submit
mode and I can't l comp.lang.perl.* right now..  Or is that a question
already answered exhaustively?

>I have a string varible called $test_proj_n_page =
>gridSearch/pgHomeDefault?
>
>I am trying to do the following:
>
>1) drop the ? from the end of the line.

	$test_proj_n_page =~ s/^(.*?)\?$/$1/g;

>2) split the remaining 'gridSearch/pgHomeDefault' into
>    two variables containing the following:
>
>   $test_projectname = gridSearch
>   $test_pagename    = pgHomeDefault

	($test_projectname, $test_pagename) = split(/\//, $test_proj_n_page);

>I have the O'Reilly book 'Prgramming Perl' and I have not run across a
>way to do this
>or I am overlooking the answer to it. If you have a suggestion on how to
>do this
>I would greatly appreciate it.

	You _are_ overlooking it, or not really understanding what you're
trying to do.  You want to strip a character off the end of a response?
you could chop() it, but what if the line doesn't have the '?' at the end.
Use a regex (and read up in the regex section in Camel, or perldoc
perlre).

	Converting a delimited string into a list?  That's also in Camel,
as well as in perldoc perlfunc (try hitting '/split [A-Z]' once the top of
the page appears).

	Consider picking up 'Learning Perl' (the Llama book) and reading
that from cover to cover.  Not as dense or assuming as Camel, it would
have answered these questions and gotten you thinking perlishly.  I'm not
kidding: the *.perl.* hierarchy is so busy and the questions so
frequently-asked that not having gone over the literature first ranges
from annoying to insulting to the residents.  And I would filter out
Abigail unless you know at least how to do signal handling or have a very
thick skin.. ;)

	You're probably going to get a lot of 'RTFM' responses to this,
and quite rightly, but you really also need to start thinking perlishly
when approaching this kind of thing.  And I'm sure I'll burnout in
answering questions eventually, but I'll try to answer them until then, if
I actually can.. ;)

ps:	If you use this code in your homework assignment, please attribute
appropriately ;)
-- 
If it sounds too good to be true, it's probably Linux.
"Fool! There is nothing Perl cannot do! NOTHING!" -Bastich
"You can never entirely stop being what you once were. That's why it's important
to be the right person today, and not put it off till tomorrow." - Larry Wall


------------------------------

Date: Tue, 28 Sep 1999 14:56:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Question
Message-Id: <MPG.125ad96d561914ed989ff2@nntp.hpl.hp.com>

In article <7sr9mv$p7h$1@nnrp1.deja.com> on Tue, 28 Sep 1999 20:50:44 
GMT, rthompson4450@my-deja.com <rthompson4450@my-deja.com> says...
> I have a string varible called $test_proj_n_page =
> gridSearch/pgHomeDefault?
> 
> I am trying to do the following:
> 
> 1) drop the ? from the end of the line.

    substr($string, -1) = "";

    $string =~ s/\?$//;

and several other ways.

> 2) split the remaining 'gridSearch/pgHomeDefault' into
>     two variables containing the following:
> 
>    $test_projectname = gridSearch
>    $test_pagename    = pgHomeDefault
> 
> I have the O'Reilly book 'Prgramming Perl' and I have not run across a
> way to do this or I am overlooking the answer to it.

One way to do this is identified in your question.  Look up 'split' in 
the index, or do

    perldoc -f split

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Tue, 28 Sep 1999 22:39:21 GMT
From: Dheera <dheera@usa.net>
Subject: Re: Perl Question
Message-Id: <7srg2o$tpt$1@nnrp1.deja.com>

__________________
$test_proj_n_page="gridSearch/pgHomeDefault?";

if($test_proj_n_page=~/([^\/]*)\/([^\/]*)\?/){
  $test_proj_n_page=~s/([^\/]*)\/([^\/]*)\?/
$test_projectname=$1;$test_pagename=$2/e;
}
print "$test_projectname\n$test_pagename;"
__________________

Hope this helps...

In article <7sr9mv$p7h$1@nnrp1.deja.com>,
  rthomp41@ford.com wrote:
> Hello - I have a perl question for  comp.lang.perl newsgroup.
>
> I have a string varible called $test_proj_n_page =
> gridSearch/pgHomeDefault?
>
> I am trying to do the following:
>
> 1) drop the ? from the end of the line.
> 2) split the remaining 'gridSearch/pgHomeDefault' into
>     two variables containing the following:
>
>    $test_projectname = gridSearch
>    $test_pagename    = pgHomeDefault
>
> I have the O'Reilly book 'Prgramming Perl' and I have not run across a
> way to do this
> or I am overlooking the answer to it. If you have a suggestion on how
to
> do this
> I would greatly appreciate it.
>
> Rob Thompson
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 28 Sep 1999 22:09:35 GMT
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: Perl Question
Message-Id: <7sreb0$9q1@courier.xilinx.com>

rthompson4450@my-deja.com wrote:
: Hello - I have a perl question for  comp.lang.perl newsgroup.

Well you've come to the right place then.

: I have a string varible called $test_proj_n_page =
: gridSearch/pgHomeDefault?

I'm sure you have some quotes around part of that somewhere.
I'll take the leap of faith that you mean:

 $test_proj_n_page = 'gridSearch/pgHomeDefault?'

: I am trying to do the following:

: 1) drop the ? from the end of the line.
: 2) split the remaining 'gridSearch/pgHomeDefault' into
:     two variables containing the following:

:    $test_projectname = gridSearch
:    $test_pagename    = pgHomeDefault

: I have the O'Reilly book 'Prgramming Perl' and I have not run across a
: way to do this

Really?  Hmmm...I have 'Programming Perl' right here.  Let's see:

On page 149 I see one way to take care of removing the last character
Page 220 gives me how to take care of splitting a string

And that doesn't even count the ways I can think of accomplishing
the same things via a regular expression (less efficient probably,
but it would accomplish the same thing)

I think telling you where to find the answers in your own book is
more useful than telling you how to fix your problem.  It helps you
learn to use your resource appropriately.

Cheers,
Jeff


-- 
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


------------------------------

Date: Tue, 28 Sep 1999 17:10:40 -0500
From: Michael Frost <msfrost@celluloidnexus.com>
Subject: reconnecting a closed pipe
Message-Id: <37F13CE0.4167A27E@celluloidnexus.com>

I've got a situation where I would like to reconnect a pipe from child
to parent after it has previously been closed. It doesn't have to be
"the same" pipe, it can be a new one. Is this possible, and if so, how
do I do it?

If you're wondering why I want to do this...

I'm writing a server which spawns off concurrent processes to execute
especially long-running blocks of code, then goes back to listening for
more tasks to manage. The status of the long-running blocks of code will
be logged in a single html file which is periodically loaded by a web
browser. I'd like to handle all error messages in the server, rather
than the children, so the thought was to have the child reconnect when
it's ready to send status data back to the parent. The problem is, since
the parent is a server, it is busy listening for new connections which
will result in the spawning of even more children.

Thanks in advance.

Mike Frost




------------------------------

Date: 28 Sep 1999 15:37:47 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Slice in scalar context
Message-Id: <m1btamd5ms.fsf@halfdome.holdit.com>

>>>>> "Tim" == Tim Kimball <kimball@stsci.edu> writes:

Tim> "Randal L. Schwartz" wrote:
>> ...
>> No such animal.  Every operator is different.  Must be learned by
>> consulting the docs, not intuition.  Well, maybe Larry can use his
>> intuition, but the rest of us have to use Larry's intuition.

Tim> Randall,

Tim> Here's what "the docs" say about context (Camel, pg. 43):

Tim> 	Generally it's quite intuitive.

Now, reread the above two paragraphs, knowing that *Larry* wrote that
sentence.

See? :)

print "Just another Perl hacker,"

-- 
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!


------------------------------

Date: 28 Sep 1999 18:50:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting weird numeric data
Message-Id: <x7zoy6y7k8.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> I'll keep posting these packed-sort examples until other people
  LR> start to.  :-)

we just aren't as famous as the ST yet. :-( we need to be written up in
a book or somewhere other than our paper. and we need a catchy
name. anyone have any suggestions? i have seen guttman/rosler sort but
however gratifying that is, it doesn't roll off the tongue and it not
likely to be used.

  LR> print map  substr($_, 1 + rindex $_, "\0") =>
  LR>       sort
  LR>       map  pack('C*' => split /\./) . "\0$_" =>

you like the rindex \0 trick. seems likes it works in many cases.

this also assumes (probably correctly) tha 1.2 sorts before 1.2.1 but
does it sort before 1.2.0? the problem space needs to be defined more
clearly.

the following  input generated the output below:
10.0
1.1
1.1.1
1.1.2
1.2
1.3
1.1.0
1.2.0
1.3.0


1.1.0
1.1
1.1.1
1.1.2
1.2.0
1.2
1.3.0
1.3
10.0

the ones with the extra .0 sort before shorter strings because
that byte is compared to the first char of the actual string of the
short version. i am not claiming it is wrong but not well defined. since
your data set had 10.0 i think it is legit to try others.

print map  substr($_, 1 + rindex $_, "\0") =>
      sort
      map  pack('C5' => split /\./) . "\0$_" =>
      <DATA>;
__END__
10.0
1.1
1.1.1
1.1.2
1.2
1.3
1.1.0
1.2.0
1.3.0
0.1
0
0.0

0
0.0
0.1
1.1
1.1.0
1.1.1
1.1.2
1.2
1.2.0
1.3
1.3.0
10.0

that seems to be better. but i think it is using the original key
appended to the string to compare 2 equivilent values created by the
padding. this sorta works but i need to look into it more to make sure
it is ok. i feel there may be a special case where this will fail.

  LR> WAGER:  No one can write a more efficient solution.

maybe a more correct solution. :-)


  LR> EXERCISES:

  LR> Modify the above to work with arbitrary 32-bit unsigned integers.

i can't count that high. but the answer is in pur paper.

  LR> Modify the above to work with unbounded unsigned integers.

this has me stumped partially. how unbounded is unbounded? if they can be
printed as ascii strings then you can do a packed sort on those strings.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: Tue, 28 Sep 1999 19:59:09 GMT
From: jeff@riverstyx.net (Jeff Magnusson)
Subject: Thread::Signal troubles
Message-Id: <37f11d30.159060214@news.infinet.net>

Hey, I'm having difficulty making an existing script that uses signals
to work with the Thread::Signals system:

Here's the REAPER function to clean up after a child exits:
(with lots of debug code).  I'm consistently gettinga -1 from waitpid,
which used to work perfectly.

How do I adapt that system call (or this function) to work properly in
the signal-handler thread?  Is there any documentation or examples out
there of using Thread::Signal properly?  The perldoc page for it
mentions complicated changes that must be made, but offers no real
help.  

Thanks!!

-- Jeff Magnusson/

--- CUT --
sub REAPER {
   my ($pid,$exit_value,$signal_num,$core_dumped);
   &log("DEBUG (REAPER): Starting...");
   $SIG{CHLD} = \&REAPER;
   &log("DEBUG (REAPER): About to reset signal handler.");
   while (($pid = waitpid(-1,&WNOHANG)) > 0) {
      &log("DEBUG (REAPER): Reaper found PID $pid");
      $exit_value  = $? >> 8;
      &log("DEBUG (REAPER): PID $pid had an exit value of
$exit_value");
      if (exists $children{$pid}) {
         &log("DEBUG (REAPER): Found a key in \%children for PID
$pid");
         delete $pipes{$pid};
         delete $children{$pid};
         $children--;
         &log("Child $pid has ended
(exit_value=$exit_value,CHILDREN=$children)");
         ($exit_value == 1) and $wait_for_queue = 1;
      } else {
         &log("DEBUG (REAPER): Child $pid has ended w/o a child
record. (exit_value=$exit_value)");
      }
   }
   &log("DEBUG (REAPER): Returning from REAPER. (last \$pid=$pid)");
}
--- CUT ---


------------------------------

Date: Tue, 28 Sep 1999 21:25:16 GMT
From: hennessy@cloud9.net (Mathew A. Hennessy)
Subject: updated AcctInfo module (NewUser, DelUser)
Message-Id: <rv2chsio3i560@corp.supernews.com>

Hi,
	I couldn't find any pre-existing passwd/shadow mangling modules
after browsing CPAN and DejaNews, so I took the AcctInfo module and
grafted user add and delete functions into it, as well as filling out the
shadow passwd functions which were missing.  A few notes:

o This is only tested on Linux, and the mods I made break other OSes.  The
  correct solution is, if you're not using Linux, fix your OS definition
  ;)
o DO NOT RUN THIS ON A LIVE OR IMPORTANT SYSTEM UNTIL YOU'VE TESTED IT
  THOROUGHLY!
o The add/delete user functionality assumes that the script will run as a
  root process.  As root user, it's up to you to determine whether you
  want to use it or not.  All I can guarantee is that there's nothing
  willfully malicious in there ;)
o Please, if you find it useful, go thru the code and fix it!  
o Please, if you find it horribly coded, have some mercy, as it's really
  my first experience with a real 'object' (I usually don't go near the
  things) in perl.
o Documentation on the new subs and functionality is nonexistent, though a
  couple of examples are provided.  Feel free to fix this!

	I tried sending the patchlist to the author's email as given in
the original (1.18) module, but I received no reply, so I'm putting a note
here in case someone else finds my mods useful.  If there's a better way
of doing this which isn't in DejaNews or easily-found in CPAN, please let
me know and I'll use that instead.

The URL: http://www.users.cloud9.net/~hennessy/AcctInfo-1.24.tar.gz

Patchlist diff'd against 1.18 available upon request.

Cheers,
- Matt

-- 
If it sounds too good to be true, it's probably Linux.
"Fool! There is nothing Perl cannot do! NOTHING!" -Bastich
"You can never entirely stop being what you once were. That's why it's important
to be the right person today, and not put it off till tomorrow." - Larry Wall


------------------------------

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 935
*************************************


home help back first fref pref prev next nref lref last post