[17110] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4522 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 4 18:10:35 2000

Date: Wed, 4 Oct 2000 15:10:18 -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: <970697418-v9-i4522@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 4 Oct 2000     Volume: 9 Number: 4522

Today's topics:
        modifying files <david@wmol.com>
    Re: modifying files <jeff@vpservices.com>
    Re: Module installation issues <tim@ipac.caltech.edu>
    Re: Need the best Perl Tutorial -- bar none <01031149@3web.net>
    Re: Need the best Perl Tutorial -- bar none (Andrew J. Perrin)
        NetResource Share Problems. <schergr@yahoo.com>
    Re: Newby questions <gene@allsysinc.com>
    Re: perl asynchronous modem on Solaris? <phil_xxx@my-deja.com>
    Re: Perl, Unix and printers (Greg Andrews)
    Re: Reverse by paragraphs - NOT! <bart.lateur@skynet.be>
    Re: Reverse by paragraphs - NOT! stdenton@my-deja.com
    Re: Reverse by paragraphs - NOT! <godzilla@stomp.stomp.tokyo>
    Re: Reverse by paragraphs - NOT! <bart.lateur@skynet.be>
    Re: Search an array <lr@hpl.hp.com>
        Searching for spaces in a string only getting the begin <hillr@ugsolutions.com>
    Re: Searching for spaces in a string only getting the b (Craig Berry)
    Re: some questions (Brandon Metcalf)
    Re: some questions stdenton@my-deja.com
    Re: some questions (Craig Berry)
    Re: some questions <lr@hpl.hp.com>
        splitting an array into a hash of sub-arrays <already_seen@my-deja.com>
    Re: splitting an array into a hash of sub-arrays stdenton@my-deja.com
        ssh and vnc on nt via perl <skippy@rhubarb.syt.org>
        SSI in a CGI <cernava@itexas.net>
    Re: Strange behavior with DESTROY and END sh_kell@my-deja.com
    Re: System call works at command line but not within CG rbfitzpa@my-deja.com
    Re: System call works at command line but not within CG <billy@erc.msstate.edu>
    Re: Telnet to Cisco AS5200 <jay@rgrs.com>
        Threads and SMP <louis@trapezoid.com>
        What does PERL stand for? <tigz@ntlworld.com>
    Re: What does PERL stand for? <jeff@vpservices.com>
    Re: What does PERL stand for? <tigz@ntlworld.com>
    Re: What does PERL stand for? <g99z44@yahoo.com>
    Re: What does PERL stand for? <bmb@ginger.libs.uga.edu>
    Re: What does PERL stand for? <tigz@ntlworld.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 4 Oct 2000 15:18:06 -0400
From: "David Hill" <david@wmol.com>
Subject: modifying files
Message-Id: <stn0hu503pfu5d@corp.supernews.com>

What is the simplest way to delete lines from the middle of a file?

Would I create a temporary file, copying to the temp file until i've reached
the part i want deleted, skip it, then continue copying?

Thanks
David




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

Date: Wed, 04 Oct 2000 12:27:38 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: modifying files
Message-Id: <39DB84AA.8F1ACF6F@vpservices.com>


David Hill wrote:
> 
> What is the simplest way to delete lines from the middle of a file?
> 

Perhaps your answer is in the section in perlfaq5 titled:

  "How do I change one line in a file/
            delete a line in a file/
            insert a line in the middle of a file/
            append to the beginning of a file?"

> Would I create a temporary file, copying to the temp file until i've reached
> the part i want deleted, skip it, then continue copying?

"Yes" on the read/skip/cointinue part of your question (with caveats for
fixed width records) and "not necessarily" on the temporary file part of
your question.  See the FAQ for why.

-- 
Jeff


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

Date: Wed, 04 Oct 2000 12:17:07 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Module installation issues
Message-Id: <39DB8233.EB7213D0@ipac.caltech.edu>

bh wrote:
> 
> In article <8rddvg$bck$1@nnrp1.deja.com>,
>   bh <bh_ent@my-deja.com> wrote:
> > While trying to install Bundle::DBI on an HP machine running 11.00 with
> > perl 5.005 I have encountered a problem with the Net::Daemon
> > RPC::PlServer portion.
> >
> > The installation reports that the syntax error is found in
> > _h2ph_pre.ph.  The exact line mentions: ".1)" as the problem on line 2
> > of the .ph file.  Sound familiar to anyone?
> >
> 
> Does anyone have any suggestions here?  Am I in the wrong newsgroup?

Sounds like some config problem, though I have no specific relevant experience.
I have no great suggestions either, except the obvious: 

- Though it shouldn't be necessary, upgrade to perl-5.6 and try again.
- Look in _h2ph_pre.ph and see if you can find the error. If it's obscure,
  post the erroneous code and see if anyone spots the problem.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 4 Oct 2000 12:10:14 -0600
From: "Duke Normandin" <01031149@3web.net>
Subject: Re: Need the best Perl Tutorial -- bar none
Message-Id: <2lKC5.3324$Jd4.28070@jekyl.ab.tac.net>

Alex Gough wrote in message <8rfeag$i7l$1@news.ox.ac.uk>...
>"Jim Wright" <jim@inatos.com> wrote in message
>news:pfmC5.1749$RB1.14124@NewsReader...


>Anyway, the moral of the story is to:
>
>1 - Keep at it, and remember that only by working at it yourself can you
>    really get anywhere.
>
>2 - Go and buy some books, and read the perl docs, rinse, then repeat.
>
>3 - Try to have fun, make your computers have shouting matches with each
>    other, draw pretty things on the screen, annoy your friends with
>    JAPHs or golf shots and never give up.


I agree with you & Jon that the on-line tutorials are somewhat light
in the ass for details. Good enough to have whetted my appetite and
learn some basics. A good book on Perl seems to be the answer... Thanks!

-duke



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

Date: 04 Oct 2000 13:15:18 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: Need the best Perl Tutorial -- bar none
Message-Id: <uya04zfx5.fsf@demog.berkeley.edu>

"Duke Normandin" <01031149@3web.net> writes:

> This newbie is in dire need of the *best* Perl Tutorial
> available on the 'net!! I've got close to a dozen
> so-so ones already. Any suggestions?
> 
> -- 
> tia....duke
> 

Personally, I'm looking for the fourth-best tutorial. Any advice?

:)

-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


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

Date: Wed, 04 Oct 2000 20:49:52 GMT
From: Greg Scher <schergr@yahoo.com>
Subject: NetResource Share Problems.
Message-Id: <8rg55d$jmi$1@nnrp1.deja.com>



Has anyone established a successful way of checking for the existance
or non-existance of a share using either NetShareGetInfo (which bombs
completly if the share doesn't exist) or NetShareCheck (which seems to
not like hidden _USER$ shares).  I am running 5.005_02 of Activestate
and I am sick of this crap ;)  Please let me know if you can help.

Regards,

Greg

--
++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++
Gregory Scher				Perot
Systems Corporation

--
++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++
Gregory Scher				Perot
Systems Corporation


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


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

Date: Wed, 04 Oct 2000 21:53:56 GMT
From: "Gene" <gene@allsysinc.com>
Subject: Re: Newby questions
Message-Id: <UFNC5.4608$Kc.229335@news.flash.net>


"Lawrence" <lawrencedeans@NoSpam.genie.co.uk> wrote in message
news:39da50ef.718216@news.freeserve.net...
> On Mon, 02 Oct 2000 19:27:58 GMT, "Gene" <gene@allsysinc.com> assisted
> me by writing:
>
> >I have notated the code so that it should make some more sense
>
> >> sub parse_form {
> >>    my($buffer,$pair,$value,@pairs,$name);
> >>    #what is my()? -- my() adjusts the scope of the variables to just
this
> >function
> Ah I see it, if a script has been parsed using my() and you want to
> call these variables you would use my($pair,$name etc.)
> Similar to local variable rather than global

Not quite. You only have to declare the variables with the my(). When you
use the variables in the code, you don't have to do anything special. All
this does is just make sure it isn't getting some sort of global variable
that is out there somewhere in memory. Also, I've never tested it, but I
think that when you exit the function, the memory for those functions is
freed up.

>
> >>    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> >>    #reads string of input from form to $buffer variable! -- very good!
>
> >>    if (length($buffer) < 4) {
> >>          $buffer = $ENV{QUERY_STRING};
> >>     }
> >>    #what does the above bit do? -- the above bit is because there are
two
> >ways to pass data from a form.
> Am I correct in saying it's like a safety measure to make sure all
> data is collected.

It's no big deal whether or not the data is collected. The reason the code
is checking both is so that it is more flexible it doesn't have to know what
method you used in the form. If it didn't get anything the first time, it
assumes you were using the other method and dumps the data it collected
previously and replaces it with the new data. The difference in the two
methods is that one places everything in the URL (QUERY_STRING), and the
other places it on the command line(STDIN).

> >>    #    you can pass them with the GET or POST methods. This tests if
the
> >first method didn't provide much data,
> >>    #    then to try the other one.  The QUERY_STRING is what is passed
in
> >the URL. You know, all that garbage that shows up?
> Yes I know the stuff you mean.
> >>   @pairs = split(/&/, $buffer);
> >>   #splits the contents of $buffer into name-value pairs and places
> >> into the array @pairs  -- very good, except one thing the name-value
pairs
> >look more like name=value.
> Ok!
> >>    foreach $pair (@pairs) {
> >>       ($name, $value) = split(/=/, $pair);
> >>   #splits each element of @pairs into name and value variables $name,
> >> $value  -- good
>
> >>       $value =~ tr/+/ /;
> >>       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> >>   #what does the above process on the $value variable do?  -- the tr///
> >thing converts all + to spaces. That is because
> >>    #   the spaces show up as + in the data passed to the script.  The
next
> >line convers all hex data into it's proper characters.
> >>    #   you will notice that often in the URL, you will see %2f or %2e
> Got it thanks
> >>       $FORM{$name} = $value;
> >>   #$name variables receive contents of $value variables  -- almost.
this
> >creates an associative array. it looks like the following:
> >>   #    $FORM{'name1'} = value1
> >>   #    $FORM{'name2'} = value2
> >>   #    this way you can get all of the form data from the $FORM
> >associative array.
> >>    }
> >> }
> I wondered how that call worked I visualised it somehow calling the
> actual form again. It does actually do this but from within an array
> Am I right in assuming that calling the form element $FORM{'name5'}
> returns the value of the name at that element.
> . i.e. $namevalue = $FORM{'name1'}
> the variable $namevalue now holds the value of that particular arrays
> element.

You are correct in the way that you use it, but I'm not sure you completely
undersand what that part of the code is doing. It is building an associative
array, just for a matter of convenience. We don't have to use $FORM{} to
hold the data. We can build it with whatever name we choose. I've had a lot
of scripts that used things like $IN{}. When these are used in the code to
get the data, it doesn't actually access the form, but it accesses the array
that we built to represent the form. Like I said, it is just a matter of
convenience.

>
> Best regards
> Lawrence
> --
> http://www.f-deans.freeserve.co.uk
> http://www.flytyer.co.uk

If you ever need any more help with any of this, just let me know any time.
It's kind of hard to find messages on the newsgroup, so if you like, go
ahead and email me. My email is gene@allsyshost.com. I am glad to help out,
as I remember how hard it was trying to teach myself Perl. It took a while,
but I am now pretty decent at it. One last note: I only get to my messages
on Monday, Wednesday, and Friday, so I may not always get back to you right
away.

Good Luck

-gene




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

Date: Wed, 04 Oct 2000 20:43:04 GMT
From: Phil xxx <phil_xxx@my-deja.com>
Subject: Re: perl asynchronous modem on Solaris?
Message-Id: <8rg4on$j9h$1@nnrp1.deja.com>

Also if I want one device to do the input and output ie use it
synchronously which device should I use.


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


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

Date: 4 Oct 2000 14:06:47 -0700
From: gerg@ncal.verio.com (Greg Andrews)
Subject: Re: Perl, Unix and printers
Message-Id: <8rg657$70t$1@ncal.verio.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> writes:
>
>You cannot disable then enable a printer queue.
>

Godzilla, your statement is completely wrong for
SVR4 Unix systems.  Even the context I deleted
does not make that statement correct.

Enable and Disable are valid actions (and commands)
for printer queues.  They control whether or not
print jobs are transferred from the queue to the
printer.  (Accept and Reject control whether or not
print jobs can enter the queue)


  -Greg


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

Date: Wed, 04 Oct 2000 18:05:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <mcsmts0v0r4ov356318iv2cq0ooloqjdv9@4ax.com>

Godzilla! wrote:

>and O.J. Simpson is innocent as Snow White.

Snow White is innocent?!?

-- 
	Bart.


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

Date: Wed, 04 Oct 2000 17:56:17 GMT
From: stdenton@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rfqvs$ac9$1@nnrp1.deja.com>

In article <8rabr2$pa4$1@nnrp1.deja.com>,
  ollie_spencer@my-deja.com wrote:
> I am trying to process a file that has the following description:
> It has a report header on each page. The data that follows the header
> consists of paragraphs of data entered sequentially from a
> manufacturing process(processing sector, when entered, data acquired,
> etc.). There's no blank lines in a paragraph, but each paragraph is
> terminated by a blank line. It's complicated by the fact that the file
> is "upside-down", with the most recent paragraph at the top, the first
> paragraph at the bottom.

$/ = '';  # slurp in a para at a time
while(<INPUT>) {
  s/HEADER//;  #eliminate header, assuming that it may be part of para
  next if /^\s*$/;  # eliminate para that is only a header
  push @paras, $_;
}
print reverse @paras;


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


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

Date: Wed, 04 Oct 2000 11:47:02 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <39DB7B26.C9D04B76@stomp.stomp.tokyo>

Bart Lateur wrote:
 
> Godzilla! wrote:
 
> >and O.J. Simpson is innocent as Snow White.
 
> Snow White is innocent?!?
 

Snow White only has seven dents in her cherry.
She is, technically, still innocent.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Wed, 04 Oct 2000 19:12:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <0uvmtsg0aiqattrfopd80i4d7rhe5g2a4g@4ax.com>

ollie_spencer@my-deja.com wrote:

>I wish I'd not mentioned the header, because it's NOT a my problem.  I
>successfully excise the header and place the headerless data into @OF,
>even the blank lines.

But it is your problem! Without header and footer, you can easily read
the file by paragraph. Now you can't. You can read it line by line, and
filter out the header and footer. But you have an array of lines. You
want an array of paragraphs.

>I can write @OF to a file, then close and reopen it for reading.
>That way WORKS. But it seems a bit clumsy!

I feel the same whay too. So, let's try to turn the array of lines into
an array of paragraphs. I assume the line ends are still there, and I
can simply concatenate the lines.

	my @paragraph = "";  # one element
	foreach(@line) {
	    if(/^$/) {
	        # blank line = new paragraph	
	        push @paragraph, "";
	    } else {
	        # append line to current paragraph
	        $paragraph[-1] .= $_;
	    }
	}
	$, = "\n";  #blank line between paragraphs
	print reverse @paragraph;

-- 
	Bart.


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

Date: Wed, 4 Oct 2000 13:18:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Search an array
Message-Id: <MPG.144530654fd6bee498ae07@nntp.hpl.hp.com>

In article <39DB36B7.FFD2DE53@texas.net> on Wed, 04 Oct 2000 13:55:03 
GMT, Tom Briles <sariq@texas.net> says...
> "Andrew N. McGuire" wrote:

 ...

> > if (grep /^foo$/ => @array) {
> >     print "we have foo!\n";
> > }

<SNIP> correction on efficiency from FAQ

And the test should be equality:

        $_ eq 'foo'

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


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

Date: Wed, 04 Oct 2000 11:29:52 -0700
From: Ron Hill <hillr@ugsolutions.com>
Subject: Searching for spaces in a string only getting the beginning of the  string
Message-Id: <39DB7720.D7AFF039@ugsolutions.com>

Hello All,
I am trying to count the number of spaces in a string. I have the code
below. However it only works at the beginning of the string not the
whole string. I got the commands ( the ones that assign the number to
$indent) from a thread here ( counting leading spaces). Well it works
well for leading spaces but not for the whole string. I removed the ^
sign thinking that it would work on the whole string but it doen't.
Does anyone know what else I am missing?

Thanks

Ron Hill

use strict;
while (<DATA>)  {
    my $indent = length sub {$_[0] =~s/(\s+)//; $1} -> ($_);
    #my $indent=length $1 if /(\s+)/;

    print "$indent\n";
    print $_;
    }

__DATA__
   this is a test
    this is a test
-----results-----

D:\scripts>ronstest.pl
3
this is a test
4
this is a test



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

Date: Wed, 04 Oct 2000 19:05:43 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Searching for spaces in a string only getting the beginning of the 
Message-Id: <stmvs7ogjgkt30@corp.supernews.com>

Ron Hill (hillr@ugsolutions.com) wrote:
: I am trying to count the number of spaces in a string.

There's a trivially easy way to do this:

  $spaceCount = $text =~ tr/ //;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: 4 Oct 2000 18:50:39 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: some questions
Message-Id: <8rfu5v$gfr$1@bcrkh13.ca.nortel.com>

[Please post separate messages for separate questions]

jonrasm@my-deja.com writes:

 > 1. Removing characters from string
 > ************************************
 > I am trying to remove some characters from
 > strings by using:
 > 
 > foreach $line (@line)
 >   {
 >   $line =~ tr/\"/ /;
 >   }
 > 
 > This results in replacing " with space.
 > How can I remove " without leaving a space?

$line =~ tr/"//d;

 > 2. Empty an array
 > *****************
 > I am currently using
 > 
 > $#scores = -1;
 > 
 > to empty the array @scores.
 > 
 > Is there another way of doig it?

@scores = ();

Brandon


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

Date: Wed, 04 Oct 2000 19:41:12 GMT
From: stdenton@my-deja.com
Subject: Re: some questions
Message-Id: <8rg14n$g1l$1@nnrp1.deja.com>

In article <8rdis9$g1f$1@nnrp1.deja.com>,
  jonrasm@my-deja.com wrote:
> I am trying to remove some characters from
> strings by using:
>
> foreach $line (@line)
>   {
>   $line =~ tr/\"/ /;
>   }
>
> This results in replacing " with space.
> How can I remove " without leaving a space?

I'm amazed that everyone missed getting rid of the loop!
  grep tr/"//d, @line;


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


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

Date: Wed, 04 Oct 2000 20:20:05 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: some questions
Message-Id: <stn47lt0j4cd16@corp.supernews.com>

stdenton@my-deja.com wrote:
: I'm amazed that everyone missed getting rid of the loop!
:   grep tr/"//d, @line;

That doesn't get rid of the loop, it just changes its syntax.  grep still
has to iterate over the list.  Also, it's widely considered bad form to
use grep or map in void context, since a result list is created only to be
thrown away[1].  The generally accepted compact form for operating on each
member of a list is:

  tr/"//d foreach @line;

[1] Whether the list is *really* generated and discarded is of course an
    implementation issue, subject to optimization.  The point is that
    *conceptually* this happens, and that the equally compact foreach
    version avoids this semantic baggage.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Wed, 4 Oct 2000 13:12:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: some questions
Message-Id: <MPG.14452eeec17da30698ae06@nntp.hpl.hp.com>

In article <Pine.GSO.4.21.0010040816490.14163-100000@crusoe.crusoe.net> 
on Wed, 4 Oct 2000 08:17:38 -0400, Jeff Pinyan <jeffp@crusoe.net> 
says...

 ...

> Wouldn't it be nice if cases of
> 
>   s/[CHARS]//g
> 
> and
> 
>   s/[CHARS]+//g
> 
> were optimized to tr/CHARS// (if [CHARS] is constant)...?

                    tr/CHARS//d

Yes, but it would give me less to complain about.  :-)

Note that for s/[CHARS]//g 'CHARS' may include metaclasses such as \w or 
[:upper:], which cannot be translated at compile time into a set of 
characters for tr/CHARS//d, because locale dependencies can change 
during execution.

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


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

Date: Wed, 04 Oct 2000 18:31:37 GMT
From: post_to_group <already_seen@my-deja.com>
Subject: splitting an array into a hash of sub-arrays
Message-Id: <8rft29$c83$1@nnrp1.deja.com>

Hello,

I have 40+ hosts that I want to fork (see other post about problems
there).  Since I don't know how many hosts I will have (hosts come and
go) and I wanted to be able to control the number of hosts per fork, I
wrote the code below to create a series of arrays, each containing the
set number of hosts.  Except the last array would contain those left
over.  The code works fine.  I was just wondering if there were a more
efficient or better way to do this?

I have seen some methods but they seem to leave off the last hosts -
that is if the ending number is odd (off from your divisor) then those
last either were getting done multiple times or skipped. That is what
took me the longest, trying to get it so that last array would just
contain the "left-overs."  So if there is a simpler or better way or if
there are improvement you can see to this code, I would be greatful to
have such suggestions.

thanks,

Adam


BEGINNING NON RELATED PART OF PROGRAM STRIPPED FOR BREVITY

# this is where you can set the size of the host array loops will also
determine how many
# forks get spawned (hosts = 100 and hosts_per_array=10, then you'll get
10 forks of 10 hosts each)
$hosts_per_array=6;

@masterhostlist = qw(host1 host2 host3 host4 host5);

# doing ping to check if server is up - don't use Net::Ping it requires
echo be enabled in inetd.conf or ICMP (which requires root privs)

# the # after "ping $host" tells ping to only try for # seconds - if it
doesnt answer straight back there is a problem
# ping exits with 0 if ok, non-zero if not.  So "! $?" means if 0 since
in perl 0 is failure so we reverse the sense...
foreach $host (@masterhostlist) {
   $ping_info = `/usr/sbin/ping $host 1 > /dev/null 2>&1`;
   print "ping exit stat for $host is $? \n";
   if (! $?) {
      push(@hosts, $host);
              }
   else {
      push(@failedhosts, $host);
         }
}

# Now that we have semi-good @hosts list, we need to split up the hosts
lists into sub-arrays of six so that each
# fork works on only $hosts_per_array hosts per fork

# counter to calculate reminder divisible by $hosts_per_array or not
$counter = 1;

# counter/index for hash of arrays each containing $hosts_per_array
hosts (or less for last one)
$hosthash_counter = 0;

# sorted array of hosts so they come out in order....
@sorthosts=sort(@hosts);

# for loop builds a hash of arrays, each of which has $hosts_per_array
hosts or less (for last one) using the hosthash_counter as the index
# for the hash - it only gets incremented for every $hosts_per_array+1
host...
for $hostname (@sorthosts) {
# if not divisible by $hosts_per_array just push onto the array which is
contained in a hash
   if ($counter%$hosts_per_array) {
      push( @{$host_hash{$hosthash_counter}}, $hostname);
                   }
   else {
# if divisible by five, ok push but then increment counter so the next
hash starts getting filled
      push( @{$host_hash{$hosthash_counter}}, $hostname);
      $hosthash_counter++;
        }
# only outside the if do we increment the raw/total counter used to
calculate if this nth host is a multiple/divisible by $hosts_per_array
   $counter++;
}

# ONCE the hash of arrays of hosts is built, we can spill out
$hosts_per_array number of forks,
# each using an array in the hash referenced by 1 thru $hosts_per_array


# REST OF THE SCRIPT CONTINUES WITH STUFF USING THE ABOVE LIKE THIS:
FORK: foreach $hosthash_counter (sort keys %host_hash)               {
 .
 .  snipped as it is unrelated to the above
 .


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


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

Date: Wed, 04 Oct 2000 19:31:24 GMT
From: stdenton@my-deja.com
Subject: Re: splitting an array into a hash of sub-arrays
Message-Id: <8rg0ic$fhh$1@nnrp1.deja.com>

In article <8rft29$c83$1@nnrp1.deja.com>,
  post_to_group <already_seen@my-deja.com> wrote:
> Hello,
>
> I have 40+ hosts that I want to fork (see other post about problems
> there).  Since I don't know how many hosts I will have (hosts come and
> go) and I wanted to be able to control the number of hosts per fork, I
> wrote the code below to create a series of arrays, each containing the
> set number of hosts.  Except the last array would contain those left
> over.  The code works fine.  I was just wondering if there were a more
> efficient or better way to do this?


use strict;
use Data::Dumper;
## assume @hosts already contains a bunch of names
my ($numSubsets, $numHosts) = (3, scalar(@hosts));
my $numInEachSubset = int($numHosts/$numSubsets) + 1;
for (my $i = 0; $i < numSubsets; $i++) {
  my @s = splice(@hosts, 0, $numInEachSubset);
  $subset[$i] = \@s;
}
$Data::Dumper::Varname = 'subset';
print Dumper(@subset);


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


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

Date: Wed, 04 Oct 2000 20:43:36 GMT
From: Todd Seidenberg <skippy@rhubarb.syt.org>
Subject: ssh and vnc on nt via perl
Message-Id: <YDMC5.34039$ib7.4881725@news1.rdc1.nj.home.com>

Hi,


I am currently trying to write a perl script on NT to do the following:


start a secure session between my NT machine and a Solaris machine, Forward remote port 5902 to local port 5902, and run a vncviewer process on my NT (local) machine against my forwarded port.


I currently have the following:

##########
#########################################
#                                       #
# Securely launch a VNC session         #
#                                       #
#########################################


####
#Do the secure remote port forwarding thingy.
####
unless  (system("ssh -v  -C -L 5902:unix_box:5902 unix_box -l username &") ) {

        print "Forwarded the Port!\nNow Run the VNC thingy\n";
}

####
# Run the vncviewer on the forwarded port...duh
####
system("vncviewer ");

######################

Unfortunately, this doesn't work quite the way I want it to. 

I do get as far as the ssh command, and I can log into the machine, however, once the vncviewer process runs, the port is no longer forward. Essentially, I can't figure out a way to execute the ssh command  and execute the vncviewer command while the ssh is in the middle of a session. I need to do this, because thats the only way to keep the port forwarded. NT doesn't support the -f 'forking' feature of ssh, either. So actually, I have no idea what to do.  

Any help would be greatly appreciated,


Thanks,

Todd
  



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

Date: Wed, 4 Oct 2000 16:07:35 -0500
From: "Cernava" <cernava@itexas.net>
Subject: SSI in a CGI
Message-Id: <8rg66b03og@enews3.newsguy.com>

Well what I'm trying to do is have a ssi page execute a cgi then the cgi out
put html with ssi tag(s) for other cgi programs that will need to be
executed to make up a complete html page...

I can't seem to get this done. The ssi page seems not to parse the out put
of the cgi only the stuff that was in the original ssi page.

By the way the server is a apache running on redhat.




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

Date: Wed, 04 Oct 2000 20:47:16 GMT
From: sh_kell@my-deja.com
Subject: Re: Strange behavior with DESTROY and END
Message-Id: <8rg50h$jkp$1@nnrp1.deja.com>

In article <39DA878E.F1A34EBA@rochester.rr.com>,
  Bob Walton <bwalton@rochester.rr.com> wrote:
> sh_kell@my-deja.com wrote:
> >
> > Ok, I have run into an interesting situation within a simple Test.pm
> > using a test.pl to run it (Perl 5.005_03; Redhat Linux 6.0). It
seems
> > that depending on how I instantiate the object it affects the order
of
> > execution of the DESTROY and END blocks. It was my understanding
that
> > END{ } was ALWAYS executed right before program exit.
> >
> > Now what I am seeing is that if I do:
> >
> > $obj = new Test;
> >
> > Then END is called before DESTROY
> >
> > If I do:
> >
> > my $obj = new Test;
> >
> > then it executes in what is suppose to be the proper order...
DESTROY
> > then END
> >
> > I am just wondering if this is suppose to occur as such, is a bug in
> > Perl itself, is a bug in OS/Perl combo, or I messed something up?
> >
> > --------------------------------------------------------------------
--
> > Test.pm
> > --------------------------------------------------------------------
--
> >
> > package Test;
> >
> > BEGIN{
> >     print __PACKAGE_, " BEGIN\n";
> > }
> >
> > sub new(){
> >     my $class = shift;
> >     my $self = bless {}, ref($class) || $class;
> >     print __PACKAGE__, " NEW\n";
> >     return $self;
> > }
> >
> > DESTROY{
> >     print __PACKAGE__, " DESTROY\n";
> > }
> >
> > END{
> >     print __PACKAGE__, " END\n";
> > }
> >
> > 1;
> > ----------------------------------------------------------------
> > test.pl
> > ---------------------------------------------------------------
> >
> > use Test;
> >
> > $test = new Test;
> >
> > -----------------------------------------------------------------
> >
> > THis gives output of:
> >
> > Test BEGIN
> > Test NEW
> > Test END
> > Test DESTROY
>
> Really???  It won't even compile.  When adding the second _ after
> PACKAGE in the BEGIN block, it then replicates your results.

Yeah, typo in there. Sorry for that. Had to retype it since the actual
code is on my Linux box and I was posting this from my Windows laptop

>
> >
> > ----------------------------------------------------------------
> >
> > Change to:
> >
> > my $test = new Test;
> >
> > and output is:
> >
> > ------------------------------------------------------------------
> >
> > Test BEGIN
> > Test NEW
> > Test DESTROY
> > Test END
> >
> > Any insight into this would be greatly appreciated. Thank you.
>
> Well, the DESTROY method gets called when an object gets destroyed.
> Destruction of the lexical variable my $test occurs when $test goes
out
> of scope.  That is right after it is created, and before the program
> ends.  The global variable $test, on the other hand, persists until it
> is destroyed in the END processing.  To see this even more clearly,
add
> a block around the my $test=... and a print statement afterwards, like
> so:
>
>    use Test;
>    {
>       my $testlexical=new Test;
>       $testglobal=new Test;
>    }
>    print "Hi from after the block\n";
>
> --
> Bob Walton


I understand that an object's destructor is called when the object goes
out of scope. My whole question is why does the class END block get
called before the DESTROY is issued for all instantiated objects of
that class?

It seems to me that the END block (being a class wide destructor)
should ALWAYS be executed after the DESTROY for the last object of that
class else all class variables cease to exist and are not available to
be used by the other remaining objects of that class.

The example above was a simplified version of my entire, more complex
problem. In the module I have, in the DESTROY method it has something
similar to:

DESTROY{
    my $self = shift;
    $self->_flush() if $objectCount == 0;
}


Where _flush() writes the latest info to the database (in this case a
number that all objects in the class update to get a unique ID). Now
since the database handle is class-wide once I reach the end of my
program it calls main::END, Class::END then DESTROY for objects (if
objects were not instantiated via 'my')

This means that once _flush() is called it cannot update the database
since the handle has been destroyed and made inaccessible.


Now in the perltoot manpage it states:

"The object destructor handles the death of each distinct object. But
sometimes you want a bit of cleanup when the entire class is shut down,
which currently only happens when the program exits. To make such a
class destructor, create a function in that class's package named END.
This works just like the end function in traditional modules, meaning
that it gets called whenever your program exits unless it execs or dies
of an uncaught signal."


I guess the exact time a program is deemed 'exited' is at the time
main::END is called which does not care that there may be other objects
of a given class left and immediately calls all ENDs on down the line
thereby destroying any class variables that those objects may have
needed.



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


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

Date: Wed, 04 Oct 2000 19:04:46 GMT
From: rbfitzpa@my-deja.com
Subject: Re: System call works at command line but not within CGI
Message-Id: <8rfv08$du6$1@nnrp1.deja.com>

I'm running into the identical problem:

/misc/somedir/test.pl works fine on the command line but it won't
execute when called via cgi. Any feedback would be appreciated.



In article <RaJC5.7177$rO1.295143@newsread1.prod.itd.earthlink.net>,
  "Mike Flaherty" <mflaherty2@earthlink.net> wrote:
> This works at the command line but not within CGI - no errors or
anything.
> Any thoughts?
>
> @args = ("touch", "/misc/www/cgi-bin/test/bogus.txt");
> system(@args);
>
>


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


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

Date: Wed, 4 Oct 2000 14:49:12 -0500
From: "Billy Chambless" <billy@erc.msstate.edu>
Subject: Re: System call works at command line but not within CGI
Message-Id: <8rg1bp$cr2$1@nntp.msstate.edu>


"NP" <nvp@spamnothanks.speakeasy.org> wrote in message
news:ehJC5.5665$wx5.164902@news2.giganews.com...
> mflaherty2@earthlink.net wrote:
> : This works at the command line but not within CGI - no errors or
anything.

> There's probably an error but you're just not handling it correctly.

> : @args = ("touch", "/misc/www/cgi-bin/test/bogus.txt");
> : system(@args);

> I'd suggest one of a couple of things:

> 1.) Read the documentation for system() and how $? is used.  Then
>     use CGI::Carp or redirect STDERR to STDOUT.
> 2.) Use backticks instead of system.

3. Go read http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html
3a. Bookmark it.




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

Date: 04 Oct 2000 17:14:37 -0400
From: Jay Rogers <jay@rgrs.com>
Subject: Re: Telnet to Cisco AS5200
Message-Id: <827l7o8g1u.fsf@shell2.shore.net>

ppopour@infoave.net writes:

> I have a script that captures the 'show modem' and 'show line' data
> from a Cisco AS5200 using Net::Telnet.  Recently I recieved a request
> to clear the modem counters weekly.  I modified the script to look and
> the DOW and sent the 'clear mod counter' command at the end of the
> script on Monday. Doesn't work.
> 
> I'm assuming that the
> 
> Clear "show modem" counters on all modems [confirm]
> 
> prompt I get back is causing the problem.

    $t->print("clear mod counter");
    $t->waitfor('/\[confirm\] ?$/');
    $t->print("Y");
    $t->waitfor($t->prompt);


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

Date: Wed, 04 Oct 2000 15:36:50 -0500
From: "Louis Z" <louis@trapezoid.com>
Subject: Threads and SMP
Message-Id: <39db8787$1_3@goliath2.newsfeeds.com>

Is there any way for Perl to take advantage of dual CPUs?  Using threads? 
Ideally, I'd be able to run some simulation programs twice as fast if they
could' use both CPUs.  Thanks.

					-Louis Z <louis@trapezoid.com>



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: Wed, 4 Oct 2000 19:58:27 +0100
From: "Tigz" <tigz@ntlworld.com>
Subject: What does PERL stand for?
Message-Id: <J5LC5.13372$L12.269531@news2-win.server.ntlworld.com>

Well i have asked my question in the subject line.

anyone know?

Mick,




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

Date: Wed, 04 Oct 2000 12:09:28 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: What does PERL stand for?
Message-Id: <39DB8068.39B8304E@vpservices.com>

Tigz wrote:
> 
> Well i have asked my question in the subject line.
> 
> anyone know?

It stands for People Exhausted by Real Lumpheads.  Lumpheads include
those who complain about how picky Usenet is when given perfectly
reasonable advice [1] and those who ask questions which are answered in
the FAQS [2] and which have been discussed and answered in this same
newsgroup in the recent past [3].

[1] for example:  you previously wrote:

> Why O' why does every body take little fits, when somebody supposidly
> abuses the usenet?

[2] for example: your current question

[3] for example: your current question

-- 
Jeff


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

Date: Wed, 4 Oct 2000 20:26:04 +0100
From: "Tigz" <tigz@ntlworld.com>
Subject: Re: What does PERL stand for?
Message-Id: <DvLC5.13446$L12.272103@news2-win.server.ntlworld.com>

U sound like a right stress head!!!!!!! sorry m8 but u r the lumphead!!!

Jeff Zucker <jeff@vpservices.com> wrote in message
news:39DB8068.39B8304E@vpservices.com...
> Tigz wrote:
> >
> > Well i have asked my question in the subject line.
> >
> > anyone know?
>
> It stands for People Exhausted by Real Lumpheads.  Lumpheads include
> those who complain about how picky Usenet is when given perfectly
> reasonable advice [1] and those who ask questions which are answered in
> the FAQS [2] and which have been discussed and answered in this same
> newsgroup in the recent past [3].
>
> [1] for example:  you previously wrote:
>
> > Why O' why does every body take little fits, when somebody supposidly
> > abuses the usenet?
>
> [2] for example: your current question
>
> [3] for example: your current question
>
> --
> Jeff




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

Date: Wed, 4 Oct 2000 12:21:03 -0700
From: "N" <g99z44@yahoo.com>
Subject: Re: What does PERL stand for?
Message-Id: <stn159q48qm71e@corp.supernews.com>

Practical Extraction and Report Language

"Tigz" <tigz@ntlworld.com> wrote in message
news:J5LC5.13372$L12.269531@news2-win.server.ntlworld.com...
> Well i have asked my question in the subject line.
>
> anyone know?
>
> Mick,
>
>




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

Date: Wed, 4 Oct 2000 15:50:39 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: What does PERL stand for?
Message-Id: <Pine.A41.4.21.0010041549360.12940-100000@ginger.libs.uga.edu>

On Wed, 4 Oct 2000, Tigz wrote:

> U sound like a right stress head!!!!!!! sorry m8 but u r the lumphead!!!

Did you happen to notice the perfectly reasonable advice in that note?

Brad



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

Date: Wed, 4 Oct 2000 20:55:05 +0100
From: "Tigz®" <tigz@ntlworld.com>
Subject: Re: What does PERL stand for?
Message-Id: <ZWLC5.13480$L12.273925@news2-win.server.ntlworld.com>


Brad Baxter <bmb@ginger.libs.uga.edu> wrote in message
news:Pine.A41.4.21.0010041549360.12940-100000@ginger.libs.uga.edu...
> On Wed, 4 Oct 2000, Tigz wrote:
>
> > U sound like a right stress head!!!!!!! sorry m8 but u r the lumphead!!!
>
> Did you happen to notice the perfectly reasonable advice in that note?
>
> Brad
>

Annnnyyyyywwwwwaaaaaayyyyyyyyy............




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

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


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