[30747] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1992 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 19 21:09:43 2008

Date: Wed, 19 Nov 2008 18:09:10 -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, 19 Nov 2008     Volume: 11 Number: 1992

Today's topics:
    Re: Connect to multiple unix servers <mvdwege.usenet@wanadoo.nl>
    Re: Connect to multiple unix servers <tzz@lifelogs.com>
    Re: Connect to multiple unix servers <ced@blv-sam-01.ca.boeing.com>
        Copy constructor and Dup method in Perl sln@netherlands.com
    Re: Copy constructor and Dup method in Perl <jimsgibson@gmail.com>
    Re: How to find all the strings in a long that are at m sln@netherlands.com
        How to find all the strings in a long that are at most  <PengYu.UT@gmail.com>
        Perl module for managing user groups (UNIX) (J.D. Baldwin)
    Re: Perl module for managing user groups (UNIX) <tim@burlyhost.com>
    Re: Perl module for managing user groups (UNIX) <smallpond@juno.com>
    Re: Perl module to generate word report <bugbear@trim_papermule.co.uk_trim>
    Re: Perl module to generate word report <1usa@llenroc.ude.invalid>
    Re: sleep(30) hangs <tzz@lifelogs.com>
    Re: Unexpected (?) try/catch Behavior <rob@robwilkerson.org>
    Re: Unexpected (?) try/catch Behavior xhoster@gmail.com
    Re: Unexpected (?) try/catch Behavior <mvdwege.usenet@wanadoo.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Nov 2008 18:00:36 +0100
From: Mart van de Wege <mvdwege.usenet@wanadoo.nl>
Subject: Re: Connect to multiple unix servers
Message-Id: <86d4grmz0r.fsf@gareth.avalon.lan>

xhoster@gmail.com writes:

> darkknight56 <preynol@twmi.rr.com> wrote:
>> On Nov 18, 1:50=A0pm, Dirk Heinrichs <dirk.heinri...@online.de> wrote:
>> > darkknight56 wrote:
>> > > Hello. =A0I'm new at perl and am faced with a =A0problem. =A0I work
>> > > wit=
>> h
>> > > multiple unix servers and I need to execute the same commands on each
>> > > of them.
>> >
>> > Debian distributed shell is your friend.
>> >
>> > HTH...
>> >
>> > =A0 =A0 =A0 =A0 Dirk
>>
>> Sorry but I'm running a recent Activestate release of perl from a
>> Windows server to the various unix servers.  From windows, I need to
>> connect to one unix server, execute some commands, logout from that
>> box then move onto the next box and repeat the process all over again.
>
> Net::Telnet?
>
Telnet is deprecated.

Net::SSH will do nicely. It requires an ssh.exe on the Winbox, but
Putty and Cygwin/OpenSSH are just another free download away.

Mart

-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.


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

Date: Wed, 19 Nov 2008 14:29:55 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Connect to multiple unix servers
Message-Id: <86k5az1mt8.fsf@lifelogs.com>

On Tue, 18 Nov 2008 09:56:25 -0800 (PST) darkknight56 <preynol@twmi.rr.com> wrote: 

d> Hello.  I'm new at perl and am faced with a  problem.  I work with
d> multiple unix servers and I need to execute the same commands on each
d> of them.  I'd like to automate this with perl so I was hoping someone
d> could point me in the right direction as to what package to use or
d> where there may be some code snippets I could learn from and modify.

Perl won't solve your problem: executing commands on a distributed
network.  Check out tools like cfengine and Puppet that specialize in
doing this (especially if the commands are not going to change much over
time).  cfengine in particular will do many of the tasks you're probably
thinking of, like monitoring/restarting/killing processes and
distributing files, without any custom work.

d> I know there is the telnet module but if I fail to connect on one
d> server, I still need to proceed onto the next one.

You can do that with Net::Telnet and Net::SSH.

Ted


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

Date: Wed, 19 Nov 2008 14:30:43 -0800 (PST)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Connect to multiple unix servers
Message-Id: <6b696491-a863-44cd-aaf7-ba43d2d771c8@r15g2000prh.googlegroups.com>

On Nov 19, 9:00 am, Mart van de Wege
 ...
> >> From windows, I need to
> >> connect to one unix server, execute some commands, logout from that
> >> box then move onto the next box and repeat the process all over again.
>
> > Net::Telnet?
>
> Telnet is deprecated.
> ...

Net::Telnet can be useful running over an ssh connection to change
passwords however.

--
Charles DeRykus



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

Date: Wed, 19 Nov 2008 20:23:50 GMT
From: sln@netherlands.com
Subject: Copy constructor and Dup method in Perl
Message-Id: <laq8i4dv2peu23jcjl0jtnsleji2rf8591@4ax.com>

Hi, I have a need for a Class copy constructor and wonder
if anybody has implemented this.

I wan't to turn a unwieldy hash into a class. It is primarily
a data object with a few methods for retreval of formatted data.
It is going to be passed around as a parameter to several methods
of a different class where data will be fleshed out. Instead of 
endless conditional testing of the hash, I thought I would just
validate it as a reference to a data class object.

But I would need a copy constructor and/or a duplicate method.
This is because the object is reused and parameters will change
and because the object might need to be saved and stored at any
particular time.

Example:

package XReS;

sub new
{
	my ($class, @args) = @_;
	my $self  = {
		.. set default params ..
	};
	if (defined($args[0]) && ref($args[0]) eq 'XReS') {
		%{$self} = %{$args[0]};
	}
	else {
		while (my ($name, $val) = splice (@args, 0, 2)) {
			.. process other args ..
		}
	}
	return bless ($self, $class);
}
sub Dup
{
	return XReS->new(shift);
}

Also, do you forsee much more memory overhead by using a 
class object instead of just a hash, possibly creating thousands?

Any other pitfalls?
Thanks.


sln



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

Date: Wed, 19 Nov 2008 17:36:55 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Copy constructor and Dup method in Perl
Message-Id: <191120081736551988%jimsgibson@gmail.com>

In article <laq8i4dv2peu23jcjl0jtnsleji2rf8591@4ax.com>,
<sln@netherlands.com> wrote:

> Hi, I have a need for a Class copy constructor and wonder
> if anybody has implemented this.

See the dclone function of the Storable module or the article 
<http://www.stonehenge.com/merlyn/UnixReview/col30.html>

-- 
Jim Gibson


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

Date: Thu, 20 Nov 2008 01:55:07 GMT
From: sln@netherlands.com
Subject: Re: How to find all the strings in a long that are at most of n different  characters of a test string?
Message-Id: <qng9i49f32pua32rti89lh9as20av4f1bc@4ax.com>

On Wed, 19 Nov 2008 15:34:17 -0800 (PST), Peng Yu <PengYu.UT@gmail.com> wrote:

>Hi,
>
>Suppose I have a long string $a, and a test string $b.
>
>I want to fine all the substrings in $a, whose length is the same as
>$b with at most n mismatches.
>
>For example, string 'abcdef' and string 'aacdxf' have two mismatches
>at the 2nd character and the 5th character.
>
>I'm wondering if this can be done easily in perl. Can I use regular
>expression to solve this problem?
>
>Thanks,
>Peng

Not easily, and probably fairly slow.
You need some heuristic algorithym.

sln

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

use strict;
use warnings;


my $str     = 'aacdxfo   sdfbsabcrxfodfbdfb';
my $pattern = 'abcdef';
my $misses  = 2;

my @tmp = split '',$pattern;
my $pstr;
for (@tmp) {
	$pstr .= "(?:$_|(.))";
}
$pstr = '('.$pstr.')';
my $rxpattern = qr/$pstr/i;

print @tmp,"\n",$rxpattern,"\n\n";

while ($str =~ /$rxpattern/g )
{
	my $cnt = 0;
	for my $i (2..(@tmp+1)) {
		last if (($cnt += defined( $-[$i])) > $misses);
	}
	if ($cnt > $misses) {
		pos($str) = $-[0]+1;
	} else {
		print "$cnt bad chars, but found a close match: '$1'\n";
	}
}

__END__



abcdef
(?i-xsm:((?:a|(.))(?:b|(.))(?:c|(.))(?:d|(.))(?:e|(.))(?:f|(.))))

2 bad chars, but found a close match: 'aacdxf'
2 bad chars, but found a close match: 'abcrxf'




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

Date: Wed, 19 Nov 2008 15:34:17 -0800 (PST)
From: Peng Yu <PengYu.UT@gmail.com>
Subject: How to find all the strings in a long that are at most of n different  characters of a test string?
Message-Id: <c3e05812-fb6e-4f9d-8e63-700685e2399e@h5g2000yqh.googlegroups.com>

Hi,

Suppose I have a long string $a, and a test string $b.

I want to fine all the substrings in $a, whose length is the same as
$b with at most n mismatches.

For example, string 'abcdef' and string 'aacdxf' have two mismatches
at the 2nd character and the 5th character.

I'm wondering if this can be done easily in perl. Can I use regular
expression to solve this problem?

Thanks,
Peng


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

Date: Wed, 19 Nov 2008 17:49:15 +0000 (UTC)
From: INVALID_SEE_SIG@example.com.invalid (J.D. Baldwin)
Subject: Perl module for managing user groups (UNIX)
Message-Id: <gg1jir$8cn$1@reader1.panix.com>



I'm looking for a module or maybe some good sample code to save me
some labor in implementing a front-end for group management.  For
example, changing a user's primary group membership from 'foo' to
'bar' or removing a user from one of his secondary groups, adding him
to a new secondary group, etc.

Seems this should be pretty straightforward, it's just that it's a lot
of code, particularly for the error-checking.  I'd rather not write it
if I can steal-- er, "reuse" it.
-- 
  _+_ From the catapult of |If anyone objects to any statement I make, I am
_|70|___:)=}- J.D. Baldwin |quite prepared not only to retract it, but also
\      /  baldwin@panix.com|to deny under oath that I ever made it.-T. Lehrer
***~~~~----------------------------------------------------------------------


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

Date: Wed, 19 Nov 2008 11:57:20 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Perl module for managing user groups (UNIX)
Message-Id: <Bc_Uk.10896$qh4.4475@newsfe04.iad>

J.D. Baldwin wrote:

> 
> 
> I'm looking for a module or maybe some good sample code to save me
> some labor in implementing a front-end for group management.  For
> example, changing a user's primary group membership from 'foo' to
> 'bar' or removing a user from one of his secondary groups, adding him
> to a new secondary group, etc.
> 
> Seems this should be pretty straightforward, it's just that it's a lot
> of code, particularly for the error-checking.  I'd rather not write it
> if I can steal-- er, "reuse" it.

What OS are you using, specifically?  There are likely commands that
will do all of the error checking, file locking, etc. for you (i.e.,
usermod, groupmod, etc.)
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 19 Nov 2008 13:28:54 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Perl module for managing user groups (UNIX)
Message-Id: <c7947162-96d1-4d0d-b04b-bdec25107b20@l14g2000yqj.googlegroups.com>

On Nov 19, 12:49 pm, INVALID_SEE_...@example.com.invalid (J.D.
Baldwin) wrote:
> I'm looking for a module or maybe some good sample code to save me
> some labor in implementing a front-end for group management.  For
> example, changing a user's primary group membership from 'foo' to
> 'bar' or removing a user from one of his secondary groups, adding him
> to a new secondary group, etc.
>
> Seems this should be pretty straightforward, it's just that it's a lot
> of code, particularly for the error-checking.  I'd rather not write it
> if I can steal-- er, "reuse" it.


webmin is written in perl.


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

Date: Wed, 19 Nov 2008 16:21:48 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Perl module to generate word report
Message-Id: <Jo-dncKC0Mzdo7nUnZ2dnUVZ8q_inZ2d@posted.plusnet>

arun wrote:
> Hi Perl Gurus,
> 
> Is there any perl module available to generate MS word report in Linux
> environment ?


You might consider generating RTF.

http://search.cpan.org/~sburke/RTF-Writer-1.11/lib/RTF/Writer.pod

   BugBear


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

Date: Wed, 19 Nov 2008 17:16:56 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl module to generate word report
Message-Id: <Xns9B5B7CF045866asu1cornelledu@127.0.0.1>

bugbear <bugbear@trim_papermule.co.uk_trim> wrote in news:Jo-
dncKC0Mzdo7nUnZ2dnUVZ8q_inZ2d@posted.plusnet:

> arun wrote:
>> Hi Perl Gurus,
>> 
>> Is there any perl module available to generate MS word report in Linux
>> environment ?
> 
> 
> You might consider generating RTF.
> 
> http://search.cpan.org/~sburke/RTF-Writer-1.11/lib/RTF/Writer.pod

Or, generate the report using HTML::Template, give the output files a .doc 
extension.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Wed, 19 Nov 2008 14:31:57 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: sleep(30) hangs
Message-Id: <86fxln1mpu.fsf@lifelogs.com>

On Tue, 18 Nov 2008 08:01:00 -0800 (PST) marathoner@sina.com wrote: 

m> I have a programs that checks emails via IMAP and then sleeps for 30
m> seconds. Occasionally, it hangs on the line where it calls sleep(30).
 ...
m> 	print "Done. See you in 30 seconds.\n\n\n";
m> 	sleep(30); # <-- this is where it hangs sometimes

sleep() may be interfering with other signal handlers.  Try 
system(sleep => 30) instead to run it as a shell command; does that make
a difference?

Ted


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

Date: Wed, 19 Nov 2008 09:54:20 -0800 (PST)
From: Rob Wilkerson <rob@robwilkerson.org>
Subject: Re: Unexpected (?) try/catch Behavior
Message-Id: <10e93b6c-10f4-4c09-a450-7cdef35c0ed5@p35g2000prm.googlegroups.com>

On Nov 19, 9:13=A0am, "Radoulov, Dimitre" <cichomit...@gmail.com> wrote:
> Rob Wilkerson wrote:
>
> [...]> I have a scenario where I need to try to insert a record into a My=
SQL
> > database and, if the insert fails due to, well, anything, then perform
> > an update instead.
>
> [...]
>
> Not answering your Perl question, but
> what's wrong with:
>
> INSERT ... ON DUPLICATE KEY UPDATE

So it turns out that I wasn't using this because it won't work (even
though I only figured that out now). The table I'm inserting/updating
has a dual primary key. That appears to be a no-no.


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

Date: 19 Nov 2008 18:14:59 GMT
From: xhoster@gmail.com
Subject: Re: Unexpected (?) try/catch Behavior
Message-Id: <20081119131539.207$WY@newsreader.com>

Rob Wilkerson <rob@robwilkerson.org> wrote:
> On Nov 19, 9:41=A0am, Peter Makholm <pe...@makholm.net> wrote:
> > Rob Wilkerson <r...@robwilkerson.org> writes:

First off, I don't agree with your tactic.  If you get a duplicate key
error, then by all means do an update instead if that is the logical thing
to do.  But if you get a "Server is currently on fire" error, I don't see
that going on to try to update is the right thing to do.



> > > The code seems to be doing exactly what I expect. That is, dropping
> > > into the catch block and performing the update where a record exists,
> > > but the errors being caught are not being suppressed. I still get a
> > > lot of:
> >
> > > DBD::mysql::st execute failed: Duplicate entry '121993-14196' for key
> > > 1 at ./get_metrics.pl line 247.
> >
> > Being in a try block does not prevent DBI from printing error
> > messages. You have to set the PrintError attribute on you database
> > handle to 'off'.
>
> Damn. I've built this thing to reuse a single database handle, so I
> can't really do that. I might want those errors somewhere else.
>
> Thanks for the insight.

Use local to localize the effect.

{
   local $mysql->{PrintError}=0;
   ## do whatever.  Errors will not be Printed
};
# at this point, PrintError has its original value.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Wed, 19 Nov 2008 18:48:55 +0100
From: Mart van de Wege <mvdwege.usenet@wanadoo.nl>
Subject: Re: Unexpected (?) try/catch Behavior
Message-Id: <868wrfmws8.fsf@gareth.avalon.lan>

Rob Wilkerson <rob@robwilkerson.org> writes:

> On Nov 19, 9:41 am, Peter Makholm <pe...@makholm.net> wrote:
>> Rob Wilkerson <r...@robwilkerson.org> writes:
>> > The code seems to be doing exactly what I expect. That is, dropping
>> > into the catch block and performing the update where a record exists,
>> > but the errors being caught are not being suppressed. I still get a
>> > lot of:
>>
>> > DBD::mysql::st execute failed: Duplicate entry '121993-14196' for key
>> > 1 at ./get_metrics.pl line 247.
>>
>> Being in a try block does not prevent DBI from printing error
>> messages. You have to set the PrintError attribute on you database
>> handle to 'off'.
>
> Damn. I've built this thing to reuse a single database handle, so I
> can't really do that. I might want those errors somewhere else.
>
You can set the attribute anywhere you like. So you clear it to for
just the try block alone, and set it back to one afterward.

The other option is to clear PrintError and set RaiseError. That'll
make your script die on DBI errors unless you wrap your DBI method
calls in eval {} blocks. In case you want to continue on error, you
can just print the error message yourself.

I haven't used Error yet, so I don't know how it deals with DBI's
RaiseError.

Mart

-- 
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.


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

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


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