[32459] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3726 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 30 14:09:20 2012

Date: Sat, 30 Jun 2012 11:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 30 Jun 2012     Volume: 11 Number: 3726

Today's topics:
        RE: Error Handling in Net::SSH::Perl <dago_makoa@hotmail.fr>
    Re: Error Handling in Net::SSH::Perl <glex_no-spam@qwest-spam-no.invalid>
        less code best code <nospam.gravitalsun.extraantispam@hotmail.nospam.com>
    Re: less code best code <jurgenex@hotmail.com>
    Re: less code best code <ben@morrow.me.uk>
        perlbal vs ha proxy for load balancing <gavcomedy@gmail.com>
    Re: Regex losing <br> (different from the earlier topic (Morty Abzug)
        sort in scalar context; undefined behaviour in Perl <ben@morrow.me.uk>
    Re: sort in scalar context; undefined behaviour in Perl <cal@example.invalid>
    Re: sort in scalar context; undefined behaviour in Perl <justin.1207@purestblue.com>
    Re: sort in scalar context; undefined behaviour in Perl (Randal L. Schwartz)
    Re: sort in scalar context; undefined behaviour in Perl <rweikusat@mssgmbh.com>
    Re: using HTML::Template effectively <peter@makholm.net>
    Re: using HTML::Template effectively <rweikusat@mssgmbh.com>
    Re: using HTML::Template effectively <cal@example.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Jun 2012 00:41:39 -0500
From: dagomakoa <dago_makoa@hotmail.fr>
Subject: RE: Error Handling in Net::SSH::Perl
Message-Id: <xoqdnZWcRcIOc3bSnZ2dnUVZ_sidnZ2d@giganews.com>

You generally don't call 'connect' when using Net::SSH::Perl.

When you instantiate the class, using new(), it will 'connect' or 'die'
if the socket connection fails.

yeah ! That's right

Ben > My problem is that I do express a wrong password but I do not get desired error message

use Net::SSH::Perl;
eval {
	my $ssh = Net::SSH::Perl->new("$host");
	$ssh->login("$user", "$pass");
	
};

my $error = "SSH Failed: $@" if $@;

It seems that eval does me sending anything actually $@ is NULL









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

Date: Thu, 28 Jun 2012 10:34:43 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Error Handling in Net::SSH::Perl
Message-Id: <4fec7993$0$73616$815e3792@news.qwest.net>

On 06/28/12 00:41, dagomakoa wrote:
> You generally don't call 'connect' when using Net::SSH::Perl.
>
> When you instantiate the class, using new(), it will 'connect' or 'die'
> if the socket connection fails.
>
> yeah ! That's right

Please learn how to quote.

>
> Ben>  My problem is that I do express a wrong password but I do not get desired error message
>
> use Net::SSH::Perl;
> eval {
> 	my $ssh = Net::SSH::Perl->new("$host");
> 	$ssh->login("$user", "$pass");
> 	
> };
>
> my $error = "SSH Failed: $@" if $@;
>
> It seems that eval does me sending anything actually $@ is NULL

'eval' works fine and the above code is fine.  Look at the source
for the login method, it's a setter, it doesn't actually do
anything other than set the username and password it will use
when sending the command, so it's not going to 'die'.

When you actually attempt to run something:

$ssh->cmd(...);

is where it might die. cmd() returns the output, error
mesage, and the exit status, which makes it pretty easy
to use.

Take a look at the documentation before going any further:

perldoc Net::SSH::Perl


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

Date: Fri, 29 Jun 2012 13:13:43 +0300
From: "George Mpouras" <nospam.gravitalsun.extraantispam@hotmail.nospam.com>
Subject: less code best code
Message-Id: <jsjv3a$25ak$1@news.ntua.gr>

From my experience I found out that in many cases you can replace tones of 
code using the correct data structure. Instead of fighting to "search" for 
answers  with Perl you can simple provide them. Perl is great and I love it, 
it should be on any  educational program ! 



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

Date: Fri, 29 Jun 2012 06:31:31 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: less code best code
Message-Id: <4varu7toc1nq24ocj4qugh329u5150vhco@4ax.com>

"George Mpouras" <nospam.gravitalsun.extraantispam@hotmail.nospam.com>
wrote:
>From my experience I found out that in many cases you can replace tones of 
>code using the correct data structure.

That is a very fundamental realization, welcome to the club. If your
professor tought only algorithms instead of algorithms and data
structures then you may want to ask for you money back.

Actually I think it would be difficult to talk about non-trivial
algorithms without talking about data structures. And when solving
non-trivial problems discussing and designing data structures usually
takes much more time than designing the algorithms.

> Instead of fighting to "search" for 
>answers  with Perl you can simple provide them. 

If you are talking about complex data structures then any programming
language (well, maybe except assembler) provides means to construct
those. Granted, some languages have more convenient support than others
and Perl's support isn't bad at all. But it is by no means above and
beyond other modern languages, either.

jue


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

Date: Sat, 30 Jun 2012 01:38:30 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: less code best code
Message-Id: <6du1c9-36i1.ln1@anubis.morrow.me.uk>


Quoth Jürgen Exner <jurgenex@hotmail.com>:
> 
> That is a very fundamental realization, welcome to the club. If your
> professor tought only algorithms instead of algorithms and data
> structures then you may want to ask for you money back.

This attitude is getting a little tiresome. Many (most?) of us here
(myself included) have no formal instruction in Computer Science or any
related discipline. Making snide remarks based on the assumption that
anyone who hasn't is grossly ignorant is more than a little rude.

Ben



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

Date: Thu, 28 Jun 2012 13:45:13 -0700 (PDT)
From: quiet_lad <gavcomedy@gmail.com>
Subject: perlbal vs ha proxy for load balancing
Message-Id: <63c858e6-adc5-447c-87a9-931ae0e0e36f@r3g2000yqh.googlegroups.com>

reccomendations?


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

Date: Tue, 26 Jun 2012 22:29:01 +0000 (UTC)
From: morty@red-sonja.frakir.org (Morty Abzug)
Subject: Re: Regex losing <br> (different from the earlier topic about losing $1)
Message-Id: <jsdd3d$39p$1@dont-email.me>

In article <s7pdb9-23b2.ln1@anubis.morrow.me.uk>,
"Ben Morrow " <ben@morrow.me.uk> spake thusly:
>
>     s/ (?:\s|<br>) \K \Q$original\E (?=\s|<br>) /$converted/ix;

In addition to Jan and Ben's excellent suggestions, please note that
the patterns don't need to be applied in a loop.  You can do something
like this:

my $regex=join "|", map quotemeta, @profanityArr;
$text =~ s{ (?:\s|<br>) \K ($regex) (?=\s|<br>) }{"X" x length $1}ex;

The "|" lets you match alternatives in a single regex, while the /e
flag is used to eval an expression before performing a substitution.

As I'm sure you know, folks who want to bypass the filters can usually
figure out ways around them.  :)

- Morty


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

Date: Thu, 28 Jun 2012 02:45:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: sort in scalar context; undefined behaviour in Perl
Message-Id: <dipsb9-vij.ln1@anubis.morrow.me.uk>


Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> 
> > In principle there are no nasal demons in Perl. If perl ever does
> > something undefined, that's a bug in perl (or possibly in an XS module
> > you've loaded).
> 
> That said, there's at least one case where the behaviour of perl
> (5.10.1) is not defined. The documentation of the sort operator states
> that
> 
> 	In list context, this sorts the LIST and returns the sorted
> 	list value.In scalar context, the behaviour of "sort()" is
> 	undefined.

sort in scalar context returns undef (and does no sorting), and has done
since at least 5.000 (I just checked).

There are a small number of people in the p5p community who seem to
think that putting 'undefined' in the Perl documentation, rather than
actually documenting current and potential future behaviour, is helpful.
This is what you would probably call 'FUD', and in this instance I would
agree with you. 

'Undefined', in the stdc sense, is only a useful concept when you are
standardising multiple implementations; there is only one implementation
of perl 5, there will (almost certainly) only ever *be* one
implementation (cf Ponie), and in practice the current behaviour of the
interpreter is a much better guide to probable future behaviour than the
documentation. (That is, a great many of the discrepancies between code
and documentation are eventually resolved in favour of the code, since
to do otherwise runs the risk of breaking people's working programs.)
More generally, perl's documentation is descriptive, unlike the C
standard which is prescriptive, so ideas like 'the implementation is
free to do anything it likes if you do this' simply don't apply.

In this case, I presume there was an idea at some point that sort in
scalar (void?) context could be used to sort an array in place, and
rather than explain that properly someone thought it would be better
just to throw some 'undefined's around. In fact, I very much doubt this
will ever happen, given that

    @ary = sort @ary;

is already optimised to sort in place.

Ben



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

Date: Thu, 28 Jun 2012 22:02:14 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: sort in scalar context; undefined behaviour in Perl
Message-Id: <g7ydnYi93dpbtXDSnZ2dnUVZ_q6dnZ2d@supernews.com>

On 06/27/2012 07:45 PM, Ben Morrow wrote:
>
> Quoth Rainer Weikusat<rweikusat@mssgmbh.com>:
>> Ben Morrow<ben@morrow.me.uk>  writes:
>>
>>> In principle there are no nasal demons in Perl. If perl ever does
>>> something undefined, that's a bug in perl (or possibly in an XS module
>>> you've loaded).
>>
>> That said, there's at least one case where the behaviour of perl
>> (5.10.1) is not defined. The documentation of the sort operator states
>> that
>>
>> 	In list context, this sorts the LIST and returns the sorted
>> 	list value.In scalar context, the behaviour of "sort()" is
>> 	undefined.
>
> sort in scalar context returns undef (and does no sorting), and has done
> since at least 5.000 (I just checked).

I don't have really have anything to say here;  I'm just editing the way 
I do.  I assume that rainer has something to say about this, and he can 
use this edit to do so.
>
> There are a small number of people in the p5p community who seem to
> think that putting 'undefined' in the Perl documentation, rather than
> actually documenting current and potential future behaviour, is helpful.
> This is what you would probably call 'FUD', and in this instance I would
> agree with you.

What is FUD?
>
> 'Undefined', in the stdc sense, is only a useful concept when you are
> standardising multiple implementations; there is only one implementation
> of perl 5, there will (almost certainly) only ever *be* one
> implementation (cf Ponie), and in practice the current behaviour of the
> interpreter is a much better guide to probable future behaviour than the
> documentation. (That is, a great many of the discrepancies between code
> and documentation are eventually resolved in favour of the code, since
> to do otherwise runs the risk of breaking people's working programs.)
> More generally, perl's documentation is descriptive, unlike the C
> standard which is prescriptive, so ideas like 'the implementation is
> free to do anything it likes if you do this' simply don't apply.

OK
>
> In this case, I presume there was an idea at some point that sort in
> scalar (void?) context could be used to sort an array in place, and
> rather than explain that properly someone thought it would be better
> just to throw some 'undefined's around. In fact, I very much doubt this
> will ever happen, given that
>
>      @ary = sort @ary;
>
> is already optimised to sort in place.

Ok, it might give Juergen Gleichner a stroke, but why did that sort fail 
in my last script as opposed to the ones with the a and the b?

Off to karaoke stardom ...
-- 
Cal

"Big win for US today."



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

Date: Fri, 29 Jun 2012 11:42:48 +0100
From: Justin C <justin.1207@purestblue.com>
Subject: Re: sort in scalar context; undefined behaviour in Perl
Message-Id: <8ed0c9-2v2.ln1@zem.masonsmusic.co.uk>

On 2012-06-29, Cal Dershowitz <cal@example.invalid> wrote:
>
> What is FUD?

http://lmgtfy.com/?q=fud&l=1


   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 29 Jun 2012 07:27:11 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: sort in scalar context; undefined behaviour in Perl
Message-Id: <868vf6jirk.fsf@red.stonehenge.com>

>>>>> "Ben" == Ben Morrow <ben@morrow.me.uk> writes:

Ben> In this case, I presume there was an idea at some point that sort in
Ben> scalar (void?) context could be used to sort an array in place, and
Ben> rather than explain that properly someone thought it would be better
Ben> just to throw some 'undefined's around. In fact, I very much doubt this
Ben> will ever happen, given that

Ben>     @ary = sort @ary;

Ben> is already optimised to sort in place.

There was also a patch submitted at one time (tongue-in-cheek) to have
sort in a scalar context invoke "nethack", based on a sentence in one of
the early editions of Learning Perl.

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


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

Date: Fri, 29 Jun 2012 16:16:07 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: sort in scalar context; undefined behaviour in Perl
Message-Id: <87d34icfns.fsf@sapphire.mobileactivedefense.com>

Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
>> Ben Morrow <ben@morrow.me.uk> writes:
>> 
>> > In principle there are no nasal demons in Perl. If perl ever does
>> > something undefined, that's a bug in perl (or possibly in an XS module
>> > you've loaded).
>> 
>> That said, there's at least one case where the behaviour of perl
>> (5.10.1) is not defined. The documentation of the sort operator states
>> that
>> 
>> 	In list context, this sorts the LIST and returns the sorted
>> 	list value.In scalar context, the behaviour of "sort()" is
>> 	undefined.
>
> sort in scalar context returns undef (and does no sorting), and has done
> since at least 5.000 (I just checked).
>
> There are a small number of people in the p5p community who seem to
> think that putting 'undefined' in the Perl documentation, rather than
> actually documenting current and potential future behaviour, is helpful.
> This is what you would probably call 'FUD', and in this instance I would
> agree with you.

In this instance, I wouldn't, because I never subscribed to the
opinion that "undefined" means "some kind of nameless evil man should
shy away from for fear for his immortal soul". In the given case, I
would paraphrase "undefined" as "The actual behaviour is arguably not
useful and there is no consensus regarding what kind of behaviour
could be useful instead. Therefore, the issue is left officially
undecided until future developments". And that seems a very
common-sense driven approach to me.


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

Date: Wed, 27 Jun 2012 09:25:41 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: using HTML::Template effectively
Message-Id: <87zk7pqkqy.fsf@vps1.hacking.dk>

Ben Morrow <ben@morrow.me.uk> writes:

>> It's too much work cleaning up after the nasal demons when they get on
>> your keyboard.
>
> In principle there are no nasal demons in Perl. If perl ever does
> something undefined, that's a bug in perl (or possibly in an XS module
> you've loaded).

The result of my having both compile-time and run-time effects comes
pretty close to being not really defined and not really a bug.

At least perlsub from 5.8.8 does not specify what happens when you
by-pass the run-time effects, but I'm am pretty sure it would be
considered a bug to remove this "feature" and 5.10 provided a new
keyword just to make this feature official and clear.

//Makholm 



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

Date: Wed, 27 Jun 2012 22:47:55 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: using HTML::Template effectively
Message-Id: <87zk7oe8ac.fsf@sapphire.mobileactivedefense.com>

Ben Morrow <ben@morrow.me.uk> writes:

[...]

>> It's too much work cleaning up after the nasal demons when they get on
>> your keyboard.
>
> In principle there are no nasal demons in Perl. If perl ever does
> something undefined, that's a bug in perl (or possibly in an XS module
> you've loaded).

It is generally impossible to 'do something undefined' (although
certain people who frequent C-related newsgroups apparently can't ever
get the meaning of this adjective into their head). When the C
standard states that 'in such-and-such a case, the behaviour is
undefined', this is defined as 'the C standard imposes no requirements
for this situation', or, in other words, it contains no specific
information regarding it. Insofar such information is desired, it can
usually be obtained in some other way. A C implementation which would
cause a computer to turn into a dancing icebear in some situation where
the C standard 'leaves the behaviour undefined' would not be
considered non-compliant because of this. But this doesn't mean it
such an implementation is possible and completely wild speculations
of this kind belong in the realm of fiction.

That said, there's at least one case where the behaviour of perl
(5.10.1) is not defined. The documentation of the sort operator states
that

	In list context, this sorts the LIST and returns the sorted
	list value.In scalar context, the behaviour of "sort()" is
	undefined.


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

Date: Thu, 28 Jun 2012 22:21:19 -0600
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using HTML::Template effectively
Message-Id: <yOednctGnOqisHDSnZ2dnUVZ_s-dnZ2d@supernews.com>

On 06/26/2012 02:25 PM, J. Gleixner wrote:
> On 06/26/12 14:31, Cal Dershowitz wrote:

[snip]
>  >What I hope to do with this thread is re-write it with
>> modules, as well as providing a utility to make my choice of filenames
>> less obvious, but still within the organizational scheme that will be
>> this site.
>>
>> First, though, I want to go back just a bit and clear up my last few
>> difficulties with what has gone before:
>
> First though, this has nothing to do with the Subject!!!!!!!! Folks
> who know a lot about HTML::Template just wasted their time reading
> your post.

Vielen, vielen Dank für Ihre Antwort, Jürgen, ich habe massiv für Ihre 
Fürbitte zu danken.
>
>>
>> Q1) I continue to have difficulties combining the syntax of lexical
>> variables and RE's:
>> my $word = "ceiling";
>> my @matching = map /ceiling_(\d+)\.html/, @remote_files;
>> my $html_file = "ceiling_$newnum1.html";
>>
>> How would I write those last 2 lines of code with $word instead of
>> "ceiling?"
>
> This is all you needed to post. Code showing the issue and
> your question.

Das ist Ihre Meinung.
>
> Use ${word} where you want it to occur, instead of $word.
>
> my $html_file = "${word}_$newnum1.html";
>
> Since you could have a variable $word_, you need to show
> that you really only want it to use $word.

Indeed this is the correct syntax, thank you.
-- 
Cal


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3726
***************************************


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