[32331] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3598 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 23 09:09:27 2012

Date: Mon, 23 Jan 2012 06: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           Mon, 23 Jan 2012     Volume: 11 Number: 3598

Today's topics:
    Re: Collecting specific values from hash reference <ben@morrow.me.uk>
    Re: Collecting specific values from hash reference (Tim McDaniel)
    Re: Collecting specific values from hash reference <tadmc@seesig.invalid>
    Re: find it, cut it out, find next <jwkrahn@example.com>
        Made me laugh (in a despairing sort of way)... <ben@morrow.me.uk>
    Re: ssh tunnel <hjp-usenet2@hjp.at>
    Re: ssh tunnel <derykus@gmail.com>
    Re: ssh tunnel <ben@morrow.me.uk>
    Re: When is @_ undefined? <hjp-usenet2@hjp.at>
    Re: When is @_ undefined? (Seymour J.)
    Re: When is @_ undefined? <kaz@kylheku.com>
    Re: When is @_ undefined? <hjp-usenet2@hjp.at>
    Re: When is @_ undefined? (Randal L. Schwartz)
    Re: When is @_ undefined? <kaz@kylheku.com>
    Re: When is @_ undefined? <rweikusat@mssgmbh.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 21 Jan 2012 21:09:46 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Collecting specific values from hash reference
Message-Id: <q5mru8-oig1.ln1@anubis.morrow.me.uk>


Quoth Pradeep Patra <smilesonisamal@gmail.com>:
> Hi,
>    I have a hash reference as follows:
> 
> $VAR1 = {
>     A.processor0.error       => 0
>     A.processor0.success     => 77
>     A.processor0.total        => 77
>     A.processor1.error        => 0
>     A.processor1.success      => 57
>     A.processor1.total        => 57
>     A.processor2.error        => 0
>     A.processor2.success      => 110
>     A.processor2.total        => 110
> }
> 
> I want to collect the values from the different processors(for exp:
> success value of processor0,processor1,processor2 and sum them i.e 77
> + 57 +110 = 244 ).and store in a variable $success.
> 
> If ($success == 244)
> {
>     return 1;
> } else {
>      return 0;
> }
> 
> Can anybody help me in this regard?

We've been through this before. What have you tried, and where are you
having trouble?

Ben



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

Date: Sun, 22 Jan 2012 01:19:42 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Collecting specific values from hash reference
Message-Id: <jffo7e$da6$1@reader1.panix.com>

In article
<3472868e-e3fe-4a55-aaba-32e54e5a1bbb@f11g2000yql.googlegroups.com>,
Pradeep Patra  <smilesonisamal@gmail.com> wrote:
>Hi,
>   I have a hash reference as follows:
>
>$VAR1 = {
>    A.processor0.error       => 0
>    A.processor0.success     => 77
>    A.processor0.total        => 77
>    A.processor1.error        => 0
>    A.processor1.success      => 57
>    A.processor1.total        => 57
>    A.processor2.error        => 0
>    A.processor2.success      => 110
>    A.processor2.total        => 110
>}
>
>I want to collect the values from the different processors

Then I think you have chosen a data structure that is not well-suited
for your problem -- that you would be better off having a hash
subscripted by processor0 or processor1 or processor2, the value of
which is itself a has subscripted by error or success or total.
If you do that, that would make the later collecting much easier.

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Sun, 22 Jan 2012 07:43:08 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Collecting specific values from hash reference
Message-Id: <slrnjho51a.mpv.tadmc@tadbox.sbcglobal.net>

Pradeep Patra <smilesonisamal@gmail.com> wrote:
> Hi,
>    I have a hash reference as follows:
>
> $VAR1 = {
>     A.processor0.error       => 0
>     A.processor0.success     => 77
>     A.processor0.total        => 77
>     A.processor1.error        => 0
>     A.processor1.success      => 57
>     A.processor1.total        => 57
>     A.processor2.error        => 0
>     A.processor2.success      => 110
>     A.processor2.total        => 110
> }
>
> I want to collect the values from the different processors(for exp:
> success value of processor0,processor1,processor2 


Can you collect the values from the different processors?

Is that what you are asking for help with?


> and sum them 


Are you saying that you do not know how to use addition in Perl?


> i.e 77
> + 57 +110 = 244 ).and store in a variable $success.


Are you saying that you need help making variable assignments in Perl?


> Can anybody help me in this regard?


Where is your code?

Show us what you have tried, and we will help you fix it.

If you have not tried anything, then I would suggest not posting
about it until after you have been able to find the time to try that.


As with nearly all programming jobs, the code becomes easier if you can
get to starting with the right data structure.

Fix your data structure, and the code becomes trivial:


------------------
#!/usr/bin/perl
use warnings;
use strict;

my @data = (
    { error   => 0,
      success => 77,
      total   => 77,
    },
    { error   => 0,
      success => 57,
      total   => 57,
    },
    { error   => 0,
      success => 110,
      total   => 110,
    },
);

my $sum;
$sum += $_->{success} for @data;
print "$sum\n";
------------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Sun, 22 Jan 2012 00:22:25 -0800
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: find it, cut it out, find next
Message-Id: <6HPSq.164$Rh4.34@newsfe21.iad>

Dr.Ruud wrote:
> On 2012-01-16 04:53, oldyork90 wrote:
>
>> I have a string that contains numbers and ranges of numbers, like
>>
>> '1 2 4-6 8 20 - 23' which translates as "include numbers 1, 2, 4, 5,
>> 6, 8, 20, 21, 22, 23'
>
> perl -Mstrict -wle '
> my $data = "1 2 4-6 8 20 - 23 99-100";
>
> my @data = map { s/\s+\z//, s/\A\s+//; length() ? $_ : () }
> split /([^0-9]+)/, $data;

Or just:

my @data = $data =~ /[0-9]+|-/g


John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


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

Date: Sun, 22 Jan 2012 03:34:47 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Made me laugh (in a despairing sort of way)...
Message-Id: <nncsu8-cbe2.ln1@anubis.morrow.me.uk>

http://portaudit.freebsd.org/91be81e7-3fea-11e1-afc7-2c4138874f7d.html

This is a bug which was fixed in perl 5.8.1, released in 2003.

Ben



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

Date: Sat, 21 Jan 2012 22:47:25 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: ssh tunnel
Message-Id: <slrnjhmcje.jqd.hjp-usenet2@hrunkner.hjp.at>

On 2012-01-21 20:49, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2012-01-21 17:35, Ben Morrow <ben@morrow.me.uk> wrote:
>> > Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> >> On 2012-01-17 11:46, Ben Morrow <ben@morrow.me.uk> wrote:
>> >> > Try system("ssh -f -L... ... sleep 10") instead of open3. It's important
>> >> > with -f to use 'sleep 10' rather than -N, otherwise the ssh process will
>> >> > never exit. (It doesn't seem to be very easy to find its pid to kill it
>> >> > manually.)
>> >> 
>> >> open($fh, '-|', ...) returns the pid, so does fork. The following script
>> >> works for me, at least on linux:
>> >
>> > I think you're not realising what the -f argument to ssh does. It makes
>> > ssh put itself in the background, but only after any possible need to
>> > prompt the user has been dealt with.
>> 
>> Yes, but there is no reason to use it. Perl can put processes in the
>> "background" just fine. You will notice that my little test program
>> doesn't use it.
>
> Perl can put processes in the background just fine, yes. That's not the
> issue. The issue is that sometimes ssh needs to prompt, and running it in
> the background from Perl doesn't handle that very well.

Prompting doesn't work if the script is run from cron, or from a web
server, or most other situations where I've ever needed to call ssh from
a perl script. Your assumption that it is possible to prompt isn't any
more reasonable than my assumption that the environment has been set up
correctly (remote host key in known_hosts, local public key in remote
authorized_keys, ...).


> I took the program you posted and made the following change:

"Doctor, it hurts when I do this!"

"Well, then don't do it!"


	hp

-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


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

Date: Sat, 21 Jan 2012 17:26:41 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: ssh tunnel
Message-Id: <1571f4c4-5a37-4d07-b027-57e68ff90f65@l1g2000vbc.googlegroups.com>

On Jan 17, 2:17=A0am, Peter Makholm <pe...@makholm.net> wrote:
> Dr Eberhard W Lisse <nos...@lisse.NA> writes:
>
> >> maybe I misunderstand the problem, but have you tried
> >> simply starting ssh in the background (with open or
> >> fork/exec) at the start of your script and killing it at
> >> the end?
>
> > Haven't been able to successfully do that.
>
> What did you try? How did it fail?
>
> > Have you got a working code fragment?
>
> I have written a lot of code which rather na=EFvely uses IPC::Open3 to ru=
n
> ssh as a background process. It should work for opening a tunnel.
>
> The problems I don't usual handle is that the initial connection often
> asks whether to accept the host key. In this scenario the process just
> hangs. If you just accept the hostkey by hand it works correctly.
>
> //Makholm

Off-topic a bit, but I seem to recall a workaround with /dev/null...
ah, here's
the incantation:

$ ssh -o UserKnownHostsFile=3D/dev/null \
      -o StrictHostKeyChecking=3Dno \
       ...

--
Charles DeRykus


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

Date: Sun, 22 Jan 2012 02:02:42 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: ssh tunnel
Message-Id: <2b7su8-1pj1.ln1@anubis.morrow.me.uk>


Quoth "C.DeRykus" <derykus@gmail.com>:
> 
> Off-topic a bit, but I seem to recall a workaround with /dev/null...
> ah, here's
> the incantation:
> 
> $ ssh -o UserKnownHostsFile=/dev/null \
>       -o StrictHostKeyChecking=no \
>        ...

That (effectively) turns off all host key checking, which is Very Bad
unless you're using DNSSEC (and using it correctly).

Ben



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

Date: Sat, 21 Jan 2012 22:57:28 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: When is @_ undefined?
Message-Id: <slrnjhmd68.jqd.hjp-usenet2@hrunkner.hjp.at>

On 2012-01-21 20:53, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2012-01-21 14:10, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>> >>>>>> "Peter" == Peter J Holzer <hjp-usenet2@hjp.at> writes:
>> >>> In Perl or in C? In C you are correct, in Perl you are incorrect.
>> >
>> >Peter> In Perl it isn't possible to use an uninitialized variable. Ex falso
>> >Peter> quodlibet.
>> >
>> > Ehh, what?
>> >
>> > my $x;
>> 
>> At this point $x is initialized to the value undef.
>
> You are attempting to apply the meanings of words as used in the C
> standard to Perl, where they don't apply.
>
>     ~% perl -we'my $x; print $x + 0'
>     Use of uninitialized value $x in addition (+) at -e line 1.
>
> The term 'uninitialized value', as applied to Perl, means a scalar
> containing undef.

I know what the message says and means. But in my opinion it is just
badly worded. First of all, a value cannot be "initialized", unless the
verb "initialize" has some bizarre meaning which isn't used anywhere
else in the Perl docs.
Secondly, consider:

use warnings;
my $x = 5;
$x = undef;
print $x + 0;

Claiming that $x has not been initialized is just absurd.

	hp


-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


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

Date: Sat, 21 Jan 2012 18:48:06 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: When is @_ undefined?
Message-Id: <4f1b4eb6$2$fuzhry+tra$mr2ice@news.patriot.net>

In <slrnjhl3bf.2n4.willem@toad.stack.nl>, on 01/21/2012
   at 10:03 AM, Willem <willem@toad.stack.nl> said:

>It is the latter matter that I was concerned with, as were the
>posters before me.

c 'were the' 'were some of the'

My concern was avoiding unhelpful run-time diagnostics while not
losing helpful diagnostics.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Sun, 22 Jan 2012 00:36:58 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: When is @_ undefined?
Message-Id: <20120121163241.907@kylheku.com>

On 2012-01-21, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>> On 2012-01-21 14:10, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>> >>>>>> "Peter" == Peter J Holzer <hjp-usenet2@hjp.at> writes:
>> >>> In Perl or in C? In C you are correct, in Perl you are incorrect.
>> >
>> >Peter> In Perl it isn't possible to use an uninitialized variable. Ex falso
>> >Peter> quodlibet.
>> >
>> > Ehh, what?
>> >
>> > my $x;
>> 
>> At this point $x is initialized to the value undef.
>
> You are attempting to apply the meanings of words as used in the C
> standard to Perl, where they don't apply.
>
>     ~% perl -we'my $x; print $x + 0'
>     Use of uninitialized value $x in addition (+) at -e line 1.

This is a completely useless, fucked up diagnostic. The variable was introduced
in "my", and has language-defined value (be it called "undef"). Obviously the
second occurence of $x refers to the one in "my $x"; the programmer has not
misspelled the variable.

What you want to catch is variables that do not exist (were not previously
defined or assigned).


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

Date: Sun, 22 Jan 2012 15:59:33 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: When is @_ undefined?
Message-Id: <slrnjho92m.tiq.hjp-usenet2@hrunkner.hjp.at>

On 2012-01-22 00:36, Kaz Kylheku <kaz@kylheku.com> wrote:
> On 2012-01-21, Ben Morrow <ben@morrow.me.uk> wrote:
>> Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
>>> On 2012-01-21 14:10, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>> > my $x;
>>> 
>>> At this point $x is initialized to the value undef.
>>
>> You are attempting to apply the meanings of words as used in the C
>> standard to Perl, where they don't apply.
>>
>>     ~% perl -we'my $x; print $x + 0'
>>     Use of uninitialized value $x in addition (+) at -e line 1.
>
> This is a completely useless, fucked up diagnostic. The variable was introduced
> in "my", and has language-defined value (be it called "undef"). Obviously the
> second occurence of $x refers to the one in "my $x"; the programmer has not
> misspelled the variable.
>
> What you want to catch is variables that do not exist (were not previously
> defined or assigned).

You «use strict;» to catch variables which do not exist (were not
declared).

There is currently no way to catch variables which were never assigned.
But since Perl variables always start with a determinate value, I'm not
sure whether that would be useful. There is simply no difference between 
«my $x;», «my $x = undef;» and «my $x; $x = undef;». 

It is sometimes useful to catch the use of the value «undef» in Perl,
just as it is useful to catch the use of a null pointer in C. So I don't
agree that the diagnostic is completely useless, just the wording is, as
you put it so succinctly, "fucked up".

	hp

-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


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

Date: Sun, 22 Jan 2012 07:43:11 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: When is @_ undefined?
Message-Id: <864nvnbv5c.fsf@red.stonehenge.com>

>>>>> "Peter" == Peter J Holzer <hjp-usenet2@hjp.at> writes:

Peter> On 2012-01-21 14:10, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>>> "Peter" == Peter J Holzer <hjp-usenet2@hjp.at> writes:
>>>> In Perl or in C? In C you are correct, in Perl you are incorrect.
>> 
Peter> In Perl it isn't possible to use an uninitialized variable. Ex falso
Peter> quodlibet.
>> 
>> Ehh, what?
>> 
>> my $x;

Peter> At this point $x is initialized to the value undef.

>> print 3 + $x; # using an uninitialized variable... very possible!

Peter> So you aren't using an uninitialized variable here.

Yes I am.  Within the Perl world, this is an "uninitialized variable".

Please leave your other-language prejudice at the door when you are
talking to Perl people.

-- 
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: Sun, 22 Jan 2012 17:33:55 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: When is @_ undefined?
Message-Id: <20120122093133.986@kylheku.com>

On 2012-01-22, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> Please leave your other-language prejudice at the door when you are
> talking to Perl people.

Also, complex sentences with compounded subordinate clauses, words with more
than five syllables, and your computing education in general.


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

Date: Sun, 22 Jan 2012 19:34:49 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: When is @_ undefined?
Message-Id: <87wr8jzg2u.fsf@sapphire.mobileactivedefense.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>>> "Peter" == Peter J Holzer <hjp-usenet2@hjp.at> writes:

[...]

>>> print 3 + $x; # using an uninitialized variable... very possible!
>
> Peter> So you aren't using an uninitialized variable here.
>
> Yes I am.  Within the Perl world, this is an "uninitialized
> variable".

Within your 'Perl world' maybe, but certainly not within mine. And
even in your Perl world, it isn't consistently 'an uninitialized
variable':

[rw@sapphire]~ $perl -we 'my ($c, $d, $e); $c = $c + 1; $d +=1; $e = $e . 1;'
Use of uninitialized value $c in addition (+) at -e line 1.

and amusingly,

[rw@sapphire]~ $perl -we 'our $e; $e = $e  . 1;'
Use of uninitialized value $e in concatenation (.) or string at -e line 1.

To me, this looks very much like someone trying to force his
perfectly arbitrary opinion on 'sensible coding style' onto others in
some not exactly honest way and in addition, without bothering to deal
with those pesky corner cases in the implementation ...



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

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


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