[29767] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1010 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 7 11:09:46 2007

Date: Wed, 7 Nov 2007 08:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 7 Nov 2007     Volume: 11 Number: 1010

Today's topics:
        A question of context  sheinrich@my-deja.com
    Re: A question of context <mritty@gmail.com>
    Re: A question of context  sheinrich@my-deja.com
        chromatic? <MisterPerl@gmail.com>
    Re: nat traverse <wyzelli@yahoo.com.au>
    Re: Platypus - Current Working Directory - write file <ben@morrow.me.uk>
    Re: problem installing DBD/mysql.pm <spamtrap@dot-app.org>
    Re: problem installing DBD/mysql.pm <mmccaws@comcast.net>
    Re: problems building perl modules, path question <mmccaws@comcast.net>
    Re: Replace without back reference <dtlin@andrew.cmu.edu>
        simple array dropping first element <jbl02NO@SPAMhotmail.com>
    Re: simple array dropping first element <wyzelli@yahoo.com.au>
    Re: simple array dropping first element <mritty@gmail.com>
    Re: Simple question to experts <tzz@lifelogs.com>
        three set of inputs for one subroutine <hara.acharya@gmail.com>
    Re: three set of inputs for one subroutine <josef.moellers@fujitsu-siemens.com>
    Re: three set of inputs for one subroutine <wyzelli@yahoo.com.au>
        Using perl to watch other programs <bill@ts1000.us>
    Re: Using perl to watch other programs <bill@ts1000.us>
    Re: Using perl to watch other programs <josef.moellers@fujitsu-siemens.com>
    Re: Using perl to watch other programs <ben@morrow.me.uk>
    Re: Using perl to watch other programs <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 07 Nov 2007 06:18:45 -0800
From:  sheinrich@my-deja.com
Subject: A question of context
Message-Id: <1194445125.919646.209050@z9g2000hsf.googlegroups.com>


Why does this line work as expected

print qw(A B C D E F G H)[split //, '76543210'], "\n";  # outputs
"HGFEDCBA"

but this one doesn't compile:

print (split //, 'ABCDEFGH')[split //, '76543210'], "\n";  # syntax
error at ..., near ")["

???

Is there a tweak to make the 2nd version work as well?
I tried some combinations with @(), @{} but didn't get it working.

Eplanation and remedy would both be appreciated.

TIA, Steffen



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

Date: Wed, 07 Nov 2007 06:24:05 -0800
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: A question of context
Message-Id: <1194445445.290223.224060@19g2000hsx.googlegroups.com>

On Nov 7, 9:18 am, sheinr...@my-deja.com wrote:
> Why does this line work as expected
>
> print qw(A B C D E F G H)[split //, '76543210'], "\n";  # outputs
> "HGFEDCBA"
>
> but this one doesn't compile:
>
> print (split //, 'ABCDEFGH')[split //, '76543210'], "\n";  # syntax
> error at ..., near ")["
>
> ???
>
> Is there a tweak to make the 2nd version work as well?
> I tried some combinations with @(), @{} but didn't get it working.
>
> Eplanation and remedy would both be appreciated.

If it looks like a function, it acts like a function.  What that means
is that if a function like print is immediately followed by a
parenthesis, then the parentheses enclose the arguments to the
function.  So in your example, the arguments to print stopped at
the ), and the rest therefore makes no sense.

To solve, you can either enclose everything you meant to print in
parentheses:
print ((split //, 'ABCDEFGH')[split //, '76543210'], "\n");
or stick a + in front of the first (
print +(split //, 'ABCDEFGH')[split //, '76543210'], "\n";

Paul Lalli



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

Date: Wed, 07 Nov 2007 07:16:11 -0800
From:  sheinrich@my-deja.com
Subject: Re: A question of context
Message-Id: <1194448571.014005.98870@o80g2000hse.googlegroups.com>

On Nov 7, 3:24 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Nov 7, 9:18 am, sheinr...@my-deja.com wrote:
>
>
>
> > Why does this line work as expected
>
> > print qw(A B C D E F G H)[split //, '76543210'], "\n";  # outputs
> > "HGFEDCBA"
>
> > but this one doesn't compile:
>
> > print (split //, 'ABCDEFGH')[split //, '76543210'], "\n";  # syntax
> > error at ..., near ")["
>
> > ???
>
> > Is there a tweak to make the 2nd version work as well?
> > I tried some combinations with @(), @{} but didn't get it working.
>
> > Eplanation and remedy would both be appreciated.
>
> If it looks like a function, it acts like a function.  What that means
> is that if a function like print is immediately followed by a
> parenthesis, then the parentheses enclose the arguments to the
> function.  So in your example, the arguments to print stopped at
> the ), and the rest therefore makes no sense.
>
> To solve, you can either enclose everything you meant to print in
> parentheses:
> print ((split //, 'ABCDEFGH')[split //, '76543210'], "\n");
> or stick a + in front of the first (
> print +(split //, 'ABCDEFGH')[split //, '76543210'], "\n";
>
> Paul Lalli

<slapping my forehead>
 ... and if I'd have used warnings as I usually do it would have said:
"print (...) interpreted as function"

Thanks a lot pal!



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

Date: Wed, 07 Nov 2007 16:03:45 -0000
From:  Mr P <MisterPerl@gmail.com>
Subject: chromatic?
Message-Id: <1194451425.849909.44250@t8g2000prg.googlegroups.com>

Is this a person's name?

I just started reading Perl Hacks- a must read in my mind. The tips
and advice are truly inspired. Plus I can use them as AMMO in my
company, since many of these practices I already employ (and I'm
abused by others who don't, claiming they are a waste of time)..

This book begins with

"chromatic works for O'Reilly Media..."...

I puzzled over this line for a long time, thinking perhaps they had a
publishing glitch, and it was really supposed to be some markup text
referring to text chroma attributes, like:

"<chromatic>Wally Schmedly</chromatic> works for O'Reilly Media...".

Then I turned to the cover and it said "chromatic" there also. It
didn't have the word "author" anywhere on the cover,  so the word
"chromatic" just sort of hung out there in space with no contextual
meaning except that which might be assumed, like *usually* an author
is on the cover of a book, and since it seems disjointed from the
title, perhaps it's an author's moniker.

It concerned me too that if I spent this long puzzled over line #1, in
the intro, then how could I possibly ever expect to get through the
entire text?

I'm fairly certain that "chromatic" was not a given name for a real
person. It would have made sense, therefore, to perhaps pen this as
something like:

"chromatic [1] works for O'Reilly Media..."...
  .
  .
  .
[1]- The Perl Hacker formerly known as Wally Schmedly


might have helped.

I'm still not convinced I know who or what "chromatic" is, but
research continues. They refer to a website for him; I'm optimistic I
may be enlightened therein.

Henceforth I shall be known as

 "=~", the Perl Hacker formerly known as Mister Perl.



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

Date: Wed, 07 Nov 2007 13:39:40 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com.au>
Subject: Re: nat traverse
Message-Id: <wejYi.9672$CN4.882@news-server.bigpond.net.au>

"Larry" <dontmewithme@got.it> wrote in message 
news:dontmewithme-CB4316.15491205112007@news.tin.it...
> Hi,
>
>   I've found this script script that I've found very usefull
> (http://linide.sourceforge.net/nat-traverse/), yet I'd love to use nat
> traverse to set up a udp tunnel to make a browser on host A to connect
> to apache listening on HOST B. Both HOST A and HOST B are behind NAT.
>
> ** on host A I have this:
>
> perl nat-traverse --cmd="nc -vlp 65000" 40000:host B:40001
>
> Now, "nc" is bound to nat-traverse...
>
> I use my browser to connect to 127.0.0.1:65000 ("nc" gets tha request
> and sends it to the UDP tunnel...than waits for the response from he
> tunnel)
>
> ** on HOST B I have the following:
>
> perl nat-traverse --cmd="perl mediator.pl" 40001:host A:40000
>
> mediator gets data from the UDP tunnel and make a req to apache
> (listening locally on port 80) than sends the apache response back to
> the tunnel...(whereas NC gets the response and send it to the browser)
>

<snip>

> tha thing with the whole above scenario is that "nc" exits when the
> browser closes the connection...
>
> Does anyone how to sort this out??
>
> How can I bound STDIN e STDOUT to fifo files??

Looks like you need to have a way to have the 'server' end fork another 
socket for the next request.  Check the technique for a preforking proxy 
written by Randal Schwartz in one of his columns here:

http://www.stonehenge.com/merlyn/WebTechniques/col34.html

You should be able to adapt that technique, i.e you don't need the 
compression stuff, and this assumes your OS supports forking.

-- 
P 




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

Date: Wed, 7 Nov 2007 15:01:56 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Platypus - Current Working Directory - write file
Message-Id: <4k0905-1d1.ln1@osiris.mauzo.dyndns.org>


Quoth Markus S <youcontrol@hispeed.ch>:
> On 2007-11-06 11:40 pm,  Ben Morrow said:
> 
> > Have you tried simply using a
> > Perl script instead of shell? That is, instead of start.sh, have
> > start.pl
> > 
> >     #!/usr/bin/perl
> > 
> >     use File::Spec::Functions;
> > 
> >     my $dir = catdir $ARGV[0], qw/Contents Resources/;
> >     chdir $dir;
> > 
> >     # presumably the dropped items are now in $ARGV[1]... ?
> 
> I don't want to pretend that I fully understand that code but where and 
> how do I tell Perl the content of $1 (which should contain the current 
> working directory) in this?

Do you understand Perl *at* *all*? If not, find a good beginner's book
and read it: 'Learning Perl' is recommended.

The shell puts the command-line arguments in $1, $2, ... . Perl puts
them in the array @ARGV, so $ARGV[0] above is the equivalent of $1 in
shell. The line

    my $dir = catdir $ARGV[0]. qw/Contents Resources/;

is equivalent to

    my $dir = "$ARGV[0]/Contents/Resources";

except that it is portable to systems that don't use Unix path syntax.
It's always worth being portable when it's easy: you never know when you
might need it.

Ben



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

Date: Wed, 07 Nov 2007 06:33:31 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: problem installing DBD/mysql.pm
Message-Id: <m1sl3i1e9g.fsf@dot-app.org>

mmccaws2 <mmccaws@comcast.net> writes:

> now the install seems to have installed it in my .cpan directory

Modules are never installed there. What you are looking at is a temporary
file created during the process of unzipping and building the module with
the CPAN shell.

> /home/mmcca/.cpan/Bundle/DBD/mysql.pm

That's not even a module - it's a bundle file. Little wonder Perl couldn't
load it as a DBD driver.

> so in the test script I put a lib statement.  Am I using lib correctly
> or do I need a different method to have mysql.pm visible to the DBI
> module?

When it's installed correctly, you won't need a lib statement.

Reverse course and back up a bit - you need to figure out why the module
is not installed correctly. Pay close attention to what gets printed when
you run the install - it will tell you about any errors in the process.

sherm--

-- 
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Wed, 07 Nov 2007 07:47:32 -0800
From:  mmccaws2 <mmccaws@comcast.net>
Subject: Re: problem installing DBD/mysql.pm
Message-Id: <1194450452.565290.310690@q5g2000prf.googlegroups.com>

On Nov 7, 3:33 am, Sherman Pendley <spamt...@dot-app.org> wrote:
> mmccaws2 <mmcc...@comcast.net> writes:
> > now the install seems to have installed it in my .cpan directory
>
> Modules are never installed there. What you are looking at is a temporary
> file created during the process of unzipping and building the module with
> the CPAN shell.
>
> > /home/mmcca/.cpan/Bundle/DBD/mysql.pm
>
> That's not even a module - it's a bundle file. Little wonder Perl couldn't
> load it as a DBD driver.
>
> > so in the test script I put a lib statement.  Am I using lib correctly
> > or do I need a different method to have mysql.pm visible to the DBI
> > module?
>
> When it's installed correctly, you won't need a lib statement.
>
> Reverse course and back up a bit - you need to figure out why the module
> is not installed correctly. Pay close attention to what gets printed when
> you run the install - it will tell you about any errors in the process.
>
> sherm--
>
> --
> WV News, Blogging, and Discussion:http://wv-www.com
> Cocoa programming in Perl:http://camelbones.sourceforge.net

So if I run perl Makefile.PL, make, make test, make install this
process removes the previous, or just over writes the previous.  Or is
there an uninstall process that needs to be run.

Mike



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

Date: Wed, 07 Nov 2007 07:36:24 -0800
From:  mmccaws2 <mmccaws@comcast.net>
Subject: Re: problems building perl modules, path question
Message-Id: <1194449784.238931.290970@y27g2000pre.googlegroups.com>

On Oct 29, 2:53 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ron Bergin <r...@i.frys.com>:
>
>
>
> > Try doing:
>
> > $sudobash
> > [pass your login credentials]
>
> > #perl-MCPAN -e shell
>
> > Note the difference between the $ prompt and the # prompt.
>
> It would be better to avoid performing the Makefile.PL and make steps as
> root, if possible. Since CPAN (at least recent versions) has support for
> usingsudofor make install, it would be better to take advantage of it.
>
> Ben

So, I think I have made a few mistakes here and I need to correct
them.  I had installed several modules by getting into perl -MCPAN -e
shell using sudo.  The reason is I get this error message

$ perl -MCPAN -e shell
CPAN: File::HomeDir loaded ok (v0.66)
mkdir /home/mccannm/.cpan/CPAN: Permission denied at /opt/perl_32/lib/
5.8.8/CPAN/HandleConfig.pm line 539

when I tried logging in as my self.
What happened is this, right after the reinstallation of perl, we're
on 5.8.8 now, I need to install a module that required root access.  I
had tried to install that module previously and it said trying to
install the module I needed root access.  It was the POE module for
non-blocking ping.  I used sudo perl -MCPAN -e shell to intall it.
Since then I can't install any module without using sudo perl -MCPAN -
e shell.

So I need to correct this situation before it gets any worse.  In an
ideal world of unix administration what are the practices for
installing modules when you have multiple users, each with sudo
access, that need to install modules and modules that require root
permissions.

Also, do I uninstall the ones that I have already installed as root or
do I change file permissions for directories, I really don't
understand this part of administration.

Thanks for your help
mike




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

Date: Wed, 7 Nov 2007 11:10:32 +0000 (UTC)
From: Tzy-Jye Daniel Lin <dtlin@andrew.cmu.edu>
Subject: Re: Replace without back reference
Message-Id: <fgs6e9$i2g$1@news.mixmin.net>

On Tue, 06 Nov 2007 19:50:27 -0800, howa wrote:

> On 11 6 ,   9 45 , Brian McCauley <nobul...@gmail.com> wrote:
>>
>> Not yet, but as of 5.10 [1]  you'll be able to use \K.
>>
>> $str =~ s/C\KD/F/g;
>>
>> [1]http://www.regex-engineer.org/slides/perl510_regex.html
> 
> I am using Perl 5.8.7 on Windows, when using \K, it shows:
> 
> Unrecognized escape \K passed through at C:\test.pl line 6.
> 
> any idea?

As Brian said,
    \K is not in any stable Perl at the moment.
    \K will be in Perl 5.10 when it is released.


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

Date: Wed, 07 Nov 2007 07:16:09 -0600
From: jbl <jbl02NO@SPAMhotmail.com>
Subject: simple array dropping first element
Message-Id: <d3e3j3pb67lhrjbqb878i0hqdejumb1651@4ax.com>

This should be simple but I don't see it.

When the print statement outputs to the command window it is dropping
the first element (Bayer) and printing 

ocean isle beach 
Dominican Republic  
ailey 
tisdale 
O'Malley 
finley 
zeff 
brunner 
rowan 
Stella 
jessie 



use warnings;
use strict;
my @newWords;

while (<DATA>) {
     @newWords = <DATA>;

     foreach my $newWords (@newWords) {
          print $newWords;
     }
} 

__DATA__
Bayer 
ocean isle beach 
Dominican Republic  
ailey 
tisdale 
O'Malley 
finley 
zeff 
brunner 
rowan 
Stella 
jessie 

Thanks
jbl


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

Date: Wed, 07 Nov 2007 13:26:48 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com.au>
Subject: Re: simple array dropping first element
Message-Id: <s2jYi.9664$CN4.2210@news-server.bigpond.net.au>

"jbl" <jbl02NO@SPAMhotmail.com> wrote in message 
news:d3e3j3pb67lhrjbqb878i0hqdejumb1651@4ax.com...
> This should be simple but I don't see it.
>
> When the print statement outputs to the command window it is dropping
> the first element (Bayer) and printing
>
> ocean isle beach
> Dominican Republic
> ailey
> tisdale
> O'Malley
> finley
> zeff
> brunner
> rowan
> Stella
> jessie
>
>
>
> use warnings;
> use strict;
> my @newWords;
>
> while (<DATA>) {

Here you read 'Bayer' and do nothing with it....

>     @newWords = <DATA>;

Here you read everything else into the array...

>     foreach my $newWords (@newWords) {
>          print $newWords;
>     }
> }
>
> __DATA__
> Bayer
> ocean isle beach

-- 
P 




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

Date: Wed, 07 Nov 2007 06:29:21 -0800
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: simple array dropping first element
Message-Id: <1194445761.013072.255950@z9g2000hsf.googlegroups.com>

On Nov 7, 8:16 am, jbl <jbl0...@SPAMhotmail.com> wrote:
> This should be simple but I don't see it.
>
> When the print statement outputs to the command window it is dropping
> the first element (Bayer) and printing
<snip>
> use warnings;
> use strict;
> my @newWords;
>
> while (<DATA>) {

This starts a loop in which one item at a time is read from __DATA__
and stored in $_.  The first time through the loop, it reads the first
item, and stores it in $_.

>      @newWords = <DATA>;

This reads EVERYTHING that hasn't yet been read into @newWords.

>      foreach my $newWords (@newWords) {
>           print $newWords;
>      }
>
> }

You're trying to combine two different ways of doing it.  Either read
and process one line at a time, or read everything in at once and then
loop through them to process.  You can't just munge them together.

Either:
while (my $newWord = <DATA>) {
   print $newWord;
}

Or:
my @newWords = <DATA>;
foreach my $newWord (@newWords) {
   print $newWord;
}

The first way is preferred, as there's no need to read everything into
memory at once.

Paul Lalli



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

Date: Wed, 07 Nov 2007 09:44:11 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Simple question to experts
Message-Id: <m2ejf2t60k.fsf@lifelogs.com>

On Tue, 06 Nov 2007 09:30:21 -0800 Jim Gibson <jimsgibson@gmail.com> wrote: 

JG> In article <slrnfivinv.v0j.tadmc@tadmc30.sbcglobal.net>, Tad McClellan
JG> <tadmc@seesig.invalid> wrote:

>> Paul Lalli <mritty@gmail.com> wrote:
>> 
>> > It's my birthday,
>> 
>> 
>> Those are good for you.
>> 
>> A federally funded study has shown that people with the most birthdays...
>> 
>> ...
>> 
>> ...
>> 
>> ... live the longest.

JG> But did they find a causal relationship, or was it more of a
JG> statistical correlation?

It's causal.  Those pesky February 29 birthdays keep throwing the
statistics off :)

Ted


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

Date: Wed, 07 Nov 2007 13:42:23 -0000
From:  king <hara.acharya@gmail.com>
Subject: three set of inputs for one subroutine
Message-Id: <1194442943.106195.197520@v23g2000prn.googlegroups.com>

Hi,

I have a subroutine as below.And I want to give three different set of
inputs to that. And I want to save the output which I got by feeding
three set of different inputs to the subroutine.

I want to use the same subroutine for the below inputs.
1st set: $1, $2,  $3
2nd set: $4, $5, $6
3rd set: $7, $8, $9

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

sub calc
{

my $BinaryBusString = sprintf "%08b", $1;
my $BinaryDevString = sprintf "%05b", $2;
my $BinaryFuncString = sprintf "%03b", $3;
my $temp=join('','0000',$BinaryBusString,$BinaryDevString,
$BinaryFuncString,'000000000000');

my $hex = '';

while ($temp =~ s/(\d{4})$//)
	{
		$hex = sprintf('%X', oct("0b$1")).$hex;
	}
unless ($temp eq '')
	{
 		$hex = sprintf('%X', oct("0b$temp")).$hex;
   	}
$hex=~s/0/E/i;


my $Resv_Process_Bridge=$hex;
my $count_Bridge=1;
my $Resv_Bridge=40;
my $output;
my $last_string;
& nvpci;

sub nvpci
	{
		$Resv_Process_Bridge=~s/..$/$Resv_Bridge/i;
		$output=`gsdk pd $Resv_Process_Bridge`;
		$last_string = substr("$output", 72,2);
	}

while ($last_string!="10")
	{
		$count_Bridge = $count_Bridge+1;
		if ($count_Bridge == 15)
			{
				print "count is: $count_Bridge and may be a wrong input is being
given\n";
				last;
			}
		$Resv_Bridge= substr("$output", 70,2);
		& nvpci;
	}
if($count_Bridge < 10)
	{
		&Calcuate_Bridge_Register;
	}
sub Calcuate_Bridge_Register
	{
		my $output_1=sprintf "%08X\n",oct("0x$Resv_Process_Bridge")
+oct("0x08");
		my $output_2=sprintf "%08X\n",oct("0x$Resv_Process_Bridge")
+oct("0x10");
		my $output_3=sprintf "%08X\n",oct("0x$hex")+oct("0xf00");
		my $output_4=sprintf "%08X\n",oct("0x$hex")+oct("0x170");

	}

}
#######################################################

I want to save all the $output_1, $output_2, $output_3 and $output_4
for all the three set of inputs.
Writing three different subroutine for three different set of inputs
is quite lengthy a process.

I am not getting the exact idea how to use the same subroutine to do
it.



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

Date: Wed, 07 Nov 2007 15:01:21 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: three set of inputs for one subroutine
Message-Id: <fgsgfj$rqt$1@nntp.fujitsu-siemens.com>

king wrote:
> Hi,
>=20
> I have a subroutine as below.And I want to give three different set of
> inputs to that. And I want to save the output which I got by feeding
> three set of different inputs to the subroutine.
>=20
> I want to use the same subroutine for the below inputs.
> 1st set: $1, $2,  $3
> 2nd set: $4, $5, $6
> 3rd set: $7, $8, $9
>=20
> #######################################
>=20
> sub calc
> {
>=20
> my $BinaryBusString =3D sprintf "%08b", $1;
> my $BinaryDevString =3D sprintf "%05b", $2;
> my $BinaryFuncString =3D sprintf "%03b", $3;

[ ... ]

> #######################################################
>=20
> I want to save all the $output_1, $output_2, $output_3 and $output_4
> for all the three set of inputs.
> Writing three different subroutine for three different set of inputs
> is quite lengthy a process.
>=20
> I am not getting the exact idea how to use the same subroutine to do
> it.

Just do what is usually done in programs: write a sub(routine) with=20
arguments:

sub calc {
     my ($bus, $dev, $func) =3D @_;

     my $BinaryBusString =3D sprintf "%08b", $bus;
     my $BinaryDevString =3D sprintf "%05b", $dev;
     my $BinaryFuncString =3D sprintf "%03b", $func;

=2E..

As to multiple return values, you can return a list from a sub(routine):

     return ($output_1, $output_2, $output_3, $output_4);
}

Note that you must then store the result either in a list of variables=20
or in an array:

my @result =3D calc($input_bus, $input_device, $input_function);
or
my ($r1, $r2, $r3, $r4) =3D calc($input_bus, $input_device, $input_functi=
on);

Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



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

Date: Wed, 07 Nov 2007 14:05:32 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com.au>
Subject: Re: three set of inputs for one subroutine
Message-Id: <MCjYi.9682$CN4.7769@news-server.bigpond.net.au>

"king" <hara.acharya@gmail.com> wrote in message 
news:1194442943.106195.197520@v23g2000prn.googlegroups.com...
> Hi,
>
> I have a subroutine as below.And I want to give three different set of
> inputs to that. And I want to save the output which I got by feeding
> three set of different inputs to the subroutine.
>
> I want to use the same subroutine for the below inputs.
> 1st set: $1, $2,  $3
> 2nd set: $4, $5, $6
> 3rd set: $7, $8, $9
>
> #######################################


I would caution against really using $1, $2 etc since they are used in 
capturing.  But to demonstrate the syntax...

you call the sub by

calc($one, $two, $three); # more meaningful names would be helpful...

Those three values are passed into the sub via the @_ special array and can 
be accessed a number of ways, by shifting them off the array into lexical 
variables (preferred) by a slice of the @_ array (@_[0] ) or similar.  So 
inside the sub you would then write something like..



> sub calc {

my ($one, $two, $three) = @_; # this gets all of them...

And then use them as normal.

next call of the sub would be

calc($three, $four, $five);

And those populate the $one, $two, $three variables in the sub for that 
iteration.  Hence better names would be appropriate... something that 
indicates what type of data that value represents.

> {
> my $output_1=sprintf "%08X\n",oct("0x$Resv_Process_Bridge")
> +oct("0x08");
> my $output_2=sprintf "%08X\n",oct("0x$Resv_Process_Bridge")
> +oct("0x10");
> my $output_3=sprintf "%08X\n",oct("0x$hex")+oct("0xf00");
> my $output_4=sprintf "%08X\n",oct("0x$hex")+oct("0x170");
>
> }
>
> }
> #######################################################
>
> I want to save all the $output_1, $output_2, $output_3 and $output_4
> for all the three set of inputs.
> Writing three different subroutine for three different set of inputs
> is quite lengthy a process.

The subroutine will return either the last value evaluated, or a list passed 
to the 'return' function, so your last line in the subroutine may look 
something like...
(contexct of the call matters)

return($output_1, $output_2, $output_3, $output_4);

This returns a LIST made from those 4 scalars to the call... so to capture 
those values, your call needs to be somthing like...

my ($out1, $out2, $out3, $out4) = calc($one, $two, $three);

Then do something similar for the next pass of the sub...

Read perldoc perlsub

-- 
P



> I am not getting the exact idea how to use the same subroutine to do
> it.




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

Date: Wed, 07 Nov 2007 05:59:55 -0800
From:  Bill H <bill@ts1000.us>
Subject: Using perl to watch other programs
Message-Id: <1194443995.309131.86550@k79g2000hse.googlegroups.com>

Is there a way in perl to watch what is running on a server and close
out applications that appear to be hung?

I am running a perl bulletin board (YaBB) and have been having an
issue where it seems to hang occasionally and not exit, causing server
usage to go up to the point where the server locks up. While I am
trying to determine what is causing this, I would like to do is be
able to close an instance of the program if it is running for more
than 1 minute, can this be done with a perl program (maybe running as
a cron job)?


Bill H



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

Date: Wed, 07 Nov 2007 06:01:20 -0800
From:  Bill H <bill@ts1000.us>
Subject: Re: Using perl to watch other programs
Message-Id: <1194444080.097003.303770@22g2000hsm.googlegroups.com>

On Nov 7, 8:59 am, Bill H <b...@ts1000.us> wrote:
> Is there a way in perl to watch what is running on a server and close
> out applications that appear to be hung?
>
> I am running a perl bulletin board (YaBB) and have been having an
> issue where it seems to hang occasionally and not exit, causing server
> usage to go up to the point where the server locks up. While I am
> trying to determine what is causing this, I would like to do is be
> able to close an instance of the program if it is running for more
> than 1 minute, can this be done with a perl program (maybe running as
> a cron job)?
>
> Bill H

FYI this is on a linux server

Bill H



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

Date: Wed, 07 Nov 2007 15:10:38 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Using perl to watch other programs
Message-Id: <fgsh13$tm3$1@nntp.fujitsu-siemens.com>

Bill H wrote:
> On Nov 7, 8:59 am, Bill H <b...@ts1000.us> wrote:
>=20
>>Is there a way in perl to watch what is running on a server and close
>>out applications that appear to be hung?
>>
>>I am running a perl bulletin board (YaBB) and have been having an
>>issue where it seems to hang occasionally and not exit, causing server
>>usage to go up to the point where the server locks up. While I am
>>trying to determine what is causing this, I would like to do is be
>>able to close an instance of the program if it is running for more
>>than 1 minute, can this be done with a perl program (maybe running as
>>a cron job)?
>>
>>Bill H
>=20
>=20
> FYI this is on a linux server

You could have your Perl program scan the output of "ps aux" and kill=20
all processes that have a runtime of more than 1 minute.
However, as Linux boxen often live for lengthy times, there might be=20
daemons which will fall into this category sooner or later, so you might =

need to restrict which commands the target processes must be or must not =

be running.

omy @fn =3D qw (USER PID CPU MEM VSZ RSS TTY STAT START TIME COMMAND);

if (open my $psuax, 'ps aux |') {
     while (<$psuax>) {
         next if /^USER/;
	my %info;
	@info{@fn} =3D split(/\s+/, $_, scalar @fn);
	next unless $info{TIME} =3D~ /^0:/;
	kill 9, $info{PID} if $info{COMMAND} =3D~ /client/;
     }
     close $psaux;
}

--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



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

Date: Wed, 7 Nov 2007 15:14:44 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using perl to watch other programs
Message-Id: <4c1905-1d1.ln1@osiris.mauzo.dyndns.org>


Quoth Bill H <bill@ts1000.us>:
> Is there a way in perl to watch what is running on a server and close
> out applications that appear to be hung?
> 
> I am running a perl bulletin board (YaBB) and have been having an
> issue where it seems to hang occasionally and not exit, causing server
> usage to go up to the point where the server locks up. While I am
> trying to determine what is causing this, I would like to do is be
> able to close an instance of the program if it is running for more
> than 1 minute, can this be done with a perl program (maybe running as
> a cron job)?

The easiest way to do this is with setrlimit: then the OS will kill it
for you.

In general, you can use Proc::ProcessTable to see what's going on with
the other processes on the machine.

Ben



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

Date: Wed, 07 Nov 2007 09:39:08 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Using perl to watch other programs
Message-Id: <m2ir4et68z.fsf@lifelogs.com>

On Wed, 07 Nov 2007 05:59:55 -0800 Bill H <bill@ts1000.us> wrote: 

BH> Is there a way in perl to watch what is running on a server and close
BH> out applications that appear to be hung?

BH> I am running a perl bulletin board (YaBB) and have been having an
BH> issue where it seems to hang occasionally and not exit, causing server
BH> usage to go up to the point where the server locks up. While I am
BH> trying to determine what is causing this, I would like to do is be
BH> able to close an instance of the program if it is running for more
BH> than 1 minute, can this be done with a perl program (maybe running as
BH> a cron job)?

Make your application send out a heartbeat, either by network multicast
or by local IPC methods (the network multicast is generally better as it
also allows for general monitoring).  Put the process ID in the
heartbeat packet.  Send out every second or whatever.

Your process watcher looks for running processes of interest, listens
for heartbeats, and compares the heartbeat timestamp to the current
time.  If the difference is more than N seconds, kill the process.

Ted


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 1010
***************************************


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