[29048] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 292 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 2 09:14:15 2007

Date: Mon, 2 Apr 2007 06:14: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           Mon, 2 Apr 2007     Volume: 11 Number: 292

Today's topics:
    Re: multiple inheritance and instance data? <bugbear@trim_papermule.co.uk_trim>
    Re: multiple inheritance and instance data? anno4000@radom.zrz.tu-berlin.de
    Re: multiple inheritance and instance data? <hjp-usenet2@hjp.at>
    Re: multiple inheritance and instance data? anno4000@radom.zrz.tu-berlin.de
        profiling - analyse by time "on behalf of"? <bugbear@trim_papermule.co.uk_trim>
    Re: profiling - analyse by time "on behalf of"? anno4000@radom.zrz.tu-berlin.de
    Re: profiling - analyse by time "on behalf of"? <hjp-usenet2@hjp.at>
    Re: Shifting Away <hjp-usenet2@hjp.at>
        Showing who is logged on to XP <sukesh@zoom.co.uk>
    Re: Showing who is logged on to XP <wyzelli@yahoo.com>
    Re: Showing who is logged on to XP <thepoet_nospam@arcor.de>
    Re: Showing who is logged on to XP <sukesh@zoom.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 02 Apr 2007 10:19:48 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: multiple inheritance and instance data?
Message-Id: <4610cab4$0$8726$ed2619ec@ptn-nntp-reader02.plus.net>

anno4000@radom.zrz.tu-berlin.de wrote:
> Slight modification here:  A constructor can configure all it wants to
> as long as configuration doesn't also construct.
> 
> A class *must* have configuration method (an object method, often
> called ->init) to be useful.  It may have a creator, but not every
> class needs one.  It may make sense for the creator to call ->init
> automatically, as long as that isn't the only way to call ->init.

So would the hallowed "bless" call be in the creator
or the init?

   BugBear


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

Date: 2 Apr 2007 09:32:31 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: multiple inheritance and instance data?
Message-Id: <57c0tfF2bkjeqU1@mid.dfncis.de>

bugbear  <bugbear@trim_papermule.co.uk_trim> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
> > Slight modification here:  A constructor can configure all it wants to
> > as long as configuration doesn't also construct.
> > 
> > A class *must* have configuration method (an object method, often
> > called ->init) to be useful.  It may have a creator, but not every
> > class needs one.  It may make sense for the creator to call ->init
> > automatically, as long as that isn't the only way to call ->init.
> 
> So would the hallowed "bless" call be in the creator
> or the init?

In the creator.

The initializer takes an already blessed object (any object in any class)
and sets it up for use with the class it (the initializer) belongs to.
It doesn't change the bless status of an object.

Anno


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

Date: Mon, 2 Apr 2007 11:43:49 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: multiple inheritance and instance data?
Message-Id: <slrnf11k2l.o00.hjp-usenet2@yoyo.hjp.at>

On 2007-04-02 09:19, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> anno4000@radom.zrz.tu-berlin.de wrote:
>> Slight modification here:  A constructor can configure all it wants to
>> as long as configuration doesn't also construct.
>> 
>> A class *must* have configuration method (an object method, often
                                             ^^^^^^^^^^^^^^^^
>> called ->init) to be useful.  It may have a creator, but not every
>> class needs one.

I'm not sure I agree with that. I think I've run into more cases where
configuration was essentially a noop than cases where objects of a class
would never be created. It is certainly good style to always provide a
configuration method, even if it does nothing, but it isn't always
required.

>> It may make sense for the creator to call ->init automatically, as
>> long as that isn't the only way to call ->init.
>
> So would the hallowed "bless" call be in the creator
> or the init?

The creator. Otherwise there is no object on which an object method
could be called.

	hp


-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

Date: 2 Apr 2007 10:23:40 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: multiple inheritance and instance data?
Message-Id: <57c3tcF2chkr7U1@mid.dfncis.de>

Peter J. Holzer <hjp-usenet2@hjp.at> wrote in comp.lang.perl.misc:
> On 2007-04-02 09:19, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> > anno4000@radom.zrz.tu-berlin.de wrote:
> >> Slight modification here:  A constructor can configure all it wants to
> >> as long as configuration doesn't also construct.
> >> 
> >> A class *must* have configuration method (an object method, often
>                                              ^^^^^^^^^^^^^^^^
> >> called ->init) to be useful.  It may have a creator, but not every
> >> class needs one.
> 
> I'm not sure I agree with that. I think I've run into more cases where
> configuration was essentially a noop than cases where objects of a class
> would never be created.

With inside-out objects and its free subclassing it becomes more
common to have classes whose only purpose is to (optionally) add
functionality to a subclass.  An example is caching.  A cache could
be attached to individual objects as needed by initializing the object
with the cache class.  A cache object by itself wouldn't make sense.

> It is certainly good style to always provide a
> configuration method, even if it does nothing, but it isn't always
> required.

Sure, but that's a special case.  If there *is* anything to initialize,
initialization should be available separate from creation.

Anno


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

Date: Mon, 02 Apr 2007 12:38:53 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: profiling - analyse by time "on behalf of"?
Message-Id: <4610eb4d$0$8723$ed2619ec@ptn-nntp-reader02.plus.net>

I'm just trying to optimise some code.

So I'm using profiling.

Sadly, I'm missing a facility I'm used to in
common 'C'; profilers.

I know (in my real code) I'm spending
most of my time in a common subroutine.

However, this subroutine is already "fast",
and would be difficult to make faster.

So what I need to know is - who's calling it,
so I might be able to reduce the number
of times it's called.

So what I'd like to be able to do is group
the subroutine time by CALLER (or parent, if
you like).

e.g.

sub s {
 .
 ... work ...
 .
}

sub a {
     for(my $i = 0; $i < 1000; $i++) {
         s();
     }
}

sub b {
     for(my $i = 0; $i < 5000; $i++) {
         s();
     }
}

I would like a report that tells me that, of the time
spent in "s", 83% is spent working "on behalf of" b
and 17% on behalf on "a".

In this trivial case, of course, dprofpp -I
would show "s" taking 100%
of the program, with "b" taking 83 percent
and "a" taking 17%

Sadly, my real program is complex enough
that the -I output is simply confusing :-(

So - does anyone know of a profiler or profile
analyser that will do an "on behalf of"
print for me?

    BugBear


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

Date: 2 Apr 2007 11:56:31 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: profiling - analyse by time "on behalf of"?
Message-Id: <57c9bfF2c4buiU1@mid.dfncis.de>

bugbear  <bugbear@trim_papermule.co.uk_trim> wrote in comp.lang.perl.misc:
> I'm just trying to optimise some code.
> 
> So I'm using profiling.
> 
> Sadly, I'm missing a facility I'm used to in
> common 'C'; profilers.
> 
> I know (in my real code) I'm spending
> most of my time in a common subroutine.
> 
> However, this subroutine is already "fast",
> and would be difficult to make faster.
> 
> So what I need to know is - who's calling it,
> so I might be able to reduce the number
> of times it's called.
> 
> So what I'd like to be able to do is group
> the subroutine time by CALLER (or parent, if
> you like).
> 
> e.g.
> 
> sub s {
> .
> ... work ...
> .
> }
> 
> sub a {
>      for(my $i = 0; $i < 1000; $i++) {
>          s();
>      }
> }
> 
> sub b {
>      for(my $i = 0; $i < 5000; $i++) {
>          s();
>      }
> }
> 
> I would like a report that tells me that, of the time
> spent in "s", 83% is spent working "on behalf of" b
> and 17% on behalf on "a".

For a quick hack just to get the desired distribution, change the code
so that you have two subs identical to s(), say s_a() and s_b().  Call
one from a() and the other from b(), then you'll know.

Anno


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

Date: Mon, 2 Apr 2007 14:39:10 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: profiling - analyse by time "on behalf of"?
Message-Id: <slrnf11ube.s43.hjp-usenet2@yoyo.hjp.at>

On 2007-04-02 11:38, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> So what I need to know is - who's calling it,
> so I might be able to reduce the number
> of times it's called.
>
> So what I'd like to be able to do is group
> the subroutine time by CALLER (or parent, if
> you like).
[...]
> I would like a report that tells me that, of the time
> spent in "s", 83% is spent working "on behalf of" b
> and 17% on behalf on "a".
[...]
> So - does anyone know of a profiler or profile
> analyser that will do an "on behalf of"
> print for me?

I don't know one, but have a look at perldoc Devel::DProf: The format 
of the tmon.out file looks simple enough that you should be able to
extract the information you want.

	hp


-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

Date: Mon, 2 Apr 2007 09:21:27 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Shifting Away
Message-Id: <slrnf11bnn.jpd.hjp-usenet2@yoyo.hjp.at>

On 2007-04-01 05:30, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "XC" == Xiong Changnian <please@nospam.net> writes:
>  XC> In article <x7d52p2zww.fsf@mail.sysarch.com>,
>  XC>  Uri Guttman <uri@stemsystems.com> wrote:
>
>  >> first off all sub args are passed by
>  >> alias, not exactly by ref. 
>
>  XC> Yes. I think we can hammer at this distinction all night long
>  XC> without letting any more light into the room. I've tried to make
>  XC> it abundantly clear that an alias is not, as Perl defines it, a
>  XC> ref(erence). However, Perl does implement param passing via
>  XC> call-by-reference, generally speaking. Otherwise, it would not be
>  XC> possible to do anything within a sub that could clobber a param
>  XC> within the calling context.
>
> the  light needs to be shown inside your head. no one else has a problem
> with how perl handles sub args. so stop making claims that make no
> sense. 

The make sense to me (ok, maybe not in the first posting, but it got
clearer in the followups).


>  XC> Somebody at this point might say that an evil demon might pass a param 
>  XC> *value*, then look to see if $_[$i] had been changed and if so, go back 
>  XC> and put the new value back in the old mailbox. I don't know anything 
>  XC> about Perl internals but I'll bet a dollar to a doughnut that this is 
>  XC> not the case. Rather, I'll bet that $_[$i] points directly to the 
>  XC> mailbox itself. Please correct me if I'm wrong. 
>
> *boggle*

Not much to boggle about. Xiong is is correct. The alternative he
describes is usually called "call-by-value-return" or sometimes "copy in 
- copy out", but it isn't used by perl (at the moment I can't think of
any programming language (or implemention thereof) which uses this
mechanism - I know it only from the literature).


>  XC> At this, my chosen level of abstraction, there are only two ways to pass 
>  XC> a param to a sub: call-by-reference or call-by-value. Perl does the 
>  XC> former. Am I mistaken? If so, how? 
>
> you chosen level is wrong. you write perl code as if it was always call
> by value.

I think you are talking at cross-purposes here. Xiong Changnian is
talking about how the parameter passing mechanism built into perl (@_)
works, and you are talking about a common idiom to build call-by-value
on top of that.

> you pass refs if you want call by ref. sometimes you can use
> the alias nature of @_ to do call by ref but that IS NOT THE COMMON
> CASE. so drop it already and ignore that case. it doesn't matter to
> almost all the perl code out there. a very very tiny fraction uses @_ as
> a call by ref. and hopefully only by those who understand why it is
> useful

How is somebody supposed to understand why it is useful if he gets
shouted at for asking questions about it?

>  XC> It is deliberate (on the part of the Perl maintainers) and it is all the 
>  XC> time. When somebody writing code in Perl fails to understand this 
>  XC> mechanism he may, by accident, screw up -- and if foolish, blame Perl, 
>  XC> if wise, study and learn. When somebody who understands it makes 
>  XC> deliberate use of it, he may thank Larry Wall, wisely, or compliment 
>  XC> himself, foolishly. 
>
> no. most perl coders never see that nor will that. most coders are
> taught to copy @_ to lexical vars and that is call by value. simple and
> safe and proper.

Well, I wish someone had explained to me what the 

    my ($param, ...) = @_;

stuff was about. I simply cargo-culted it and found out that @_ is
call-by-reference the hard way - years after I started programming perl.

> no you have made it clear you understand the difference. what you have
> not made clear is whether you understand that the alias nature of is NOT
> IMPORTANT. no one calls perl a pass by ref lang. its common style is
> pass by value. that is what matters not how it is implemented.

I strongly disagree with that. Since it is "implemented" by the
programmer and not by perl, it is important. A perl programmer should
understand what he is writing.

	hp


-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


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

Date: 2 Apr 2007 03:17:40 -0700
From: "Suk" <sukesh@zoom.co.uk>
Subject: Showing who is logged on to XP
Message-Id: <1175509060.754566.255690@e65g2000hsc.googlegroups.com>

Hi

Is there any way in Perl I can open a port on a remote WinXP PC and
find out who is currently logged in to that PC?  Is anyone aware of
any modules which could assist in this query? Sofwtare such as
LANguard tells you who is logged on to a remote PC but I dont know how
it does this.



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

Date: Mon, 02 Apr 2007 11:03:00 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Showing who is logged on to XP
Message-Id: <Ep5Qh.7805$M.4144@news-server.bigpond.net.au>

"Suk" <sukesh@zoom.co.uk> wrote in message 
news:1175509060.754566.255690@e65g2000hsc.googlegroups.com...
> Hi
>
> Is there any way in Perl I can open a port on a remote WinXP PC and
> find out who is currently logged in to that PC?  Is anyone aware of
> any modules which could assist in this query? Sofwtare such as
> LANguard tells you who is logged on to a remote PC but I dont know how
> it does this.

analysing the result of nbtstat would be one way...

P 




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

Date: Mon, 02 Apr 2007 13:07:08 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Showing who is logged on to XP
Message-Id: <4610e3dd$0$6392$9b4e6d93@newsspool2.arcor-online.net>

Suk wrote:
> Hi
> 
> Is there any way in Perl I can open a port on a remote WinXP PC and
> find out who is currently logged in to that PC?

If the local computer also runs Windows, the easiest way is through
a WMI (Windows Management Instrumentarium) query.

> Is anyone aware of
> any modules which could assist in this query?

Win32::OLE

> Sofwtare such as
> LANguard tells you who is logged on to a remote PC but I dont know how
> it does this.

Most admin tools also utilize the WMI query interface. OS Versions
from NT4 SP4 upward support it.

Here's a little script that does that. If you want further information,
have a look at Microsoft's WMI Reference at
http://msdn2.microsoft.com/en-us/library/aa394572.aspx
which lists all available classes and properties.

------------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;
use Win32::OLE qw(in);

my $computer = $ARGV[0] || "."; # Either from command line or localhost

my $oWMIService = Win32::OLE->GetObject(
	"winmgmts:\\\\$computer\\root\\CIMV2"
	)
	or die "WMI connection failed.\n";

my $collComputers = $oWMIService->ExecQuery(
	"SELECT * FROM Win32_ComputerSystem"
	);

foreach my $comp ( in( $collComputers ) ) {
	print "Computer: " . $comp->{"Name"} . $/;
	print "User: " . $comp->{"UserName"},$/;
}
__END__
-------------------------------------------------------------------------

-Chris


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

Date: 2 Apr 2007 05:21:57 -0700
From: "Suk" <sukesh@zoom.co.uk>
Subject: Re: Showing who is logged on to XP
Message-Id: <1175516517.215420.48510@o5g2000hsb.googlegroups.com>

On 2 Apr, 12:07, Christian Winter <thepoet_nos...@arcor.de> wrote:
> Suk wrote:
> > Hi
>
> > Is there any way in Perl I can open a port on a remote WinXP PC and
> > find out who is currently logged in to that PC?
>
> If the local computer also runs Windows, the easiest way is through
> a WMI (Windows Management Instrumentarium) query.
>
> > Is anyone aware of
> > any modules which could assist in this query?
>
> Win32::OLE
>
> > Sofwtare such as
> > LANguard tells you who is logged on to a remote PC but I dont know how
> > it does this.
>
> Most admin tools also utilize the WMI query interface. OS Versions
> from NT4 SP4 upward support it.
>
> Here's a little script that does that. If you want further information,
> have a look at Microsoft's WMI Reference athttp://msdn2.microsoft.com/en-us/library/aa394572.aspx
> which lists all available classes and properties.
>
> ------------------------------------------------------------------------
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Win32::OLE qw(in);
>
> my $computer = $ARGV[0] || "."; # Either from command line or localhost
>
> my $oWMIService = Win32::OLE->GetObject(
>         "winmgmts:\\\\$computer\\root\\CIMV2"
>         )
>         or die "WMI connection failed.\n";
>
> my $collComputers = $oWMIService->ExecQuery(
>         "SELECT * FROM Win32_ComputerSystem"
>         );
>
> foreach my $comp ( in( $collComputers ) ) {
>         print "Computer: " . $comp->{"Name"} . $/;
>         print "User: " . $comp->{"UserName"},$/;}
>
> __END__
> -------------------------------------------------------------------------
>
> -Chris


Thanks for your answer. Unfortunately the localhost is running Solaris
with Perl 5.8.5 Is there anyway I could connect to the WMI port and
get the information I need?



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

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


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