[23456] in Perl-Users-Digest
Perl-Users Digest, Issue: 5671 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 16 14:10:42 2003
Date: Thu, 16 Oct 2003 11:10:14 -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 Thu, 16 Oct 2003 Volume: 10 Number: 5671
Today's topics:
newbie question about objects (John)
Re: newbie question about objects (Anno Siegel)
Re: newbie question about objects (Roy Johnson)
Re: Perl scripts for Unix on my windows machine (Ren Patterson)
Re: Perl scripts for Unix on my windows machine <bart.lateur@pandora.be>
Re: Perl scripts for Unix on my windows machine <jwillmore@remove.adelphia.net>
Re: Strange behaviour with '\r' character [[ sorry my o <nobull@mail.com>
Re: Strange behaviour with '\r' character [[ sorry my o <some@one.com>
Re: Unexpected alteration of array's content (Roy Johnson)
Re: Unexpected alteration of array's content <uri@stemsystems.com>
Re: Unexpected alteration of array's content <nobull@mail.com>
Re: XSL - 3 lines explaination -IGNORE <kaspREMOVE_CAPS@epatra.com>
XSL - 3 lines explaination <kaspREMOVE_CAPS@epatra.com>
Re: XSL - 3 lines explaination <nobull@mail.com>
Re: XSL - 3 lines explaination <kaspREMOVE_CAPS@epatra.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Oct 2003 07:04:21 -0700
From: news2003@wanadoo.es (John)
Subject: newbie question about objects
Message-Id: <3bd6db81.0310160604.770e84cb@posting.google.com>
Dear all,
I was reading about perl objects on
http://www.perldoc.com/perl5.8.0/pod/perltoot.html
and I found:
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{FULLNAME} = Fullname->new();
$self->{AGE} = undef;
$self->{PEERS} = [];
$self->{"_CENSUS"} = \$Census;
bless ($self, $class);
++ ${ $self->{"_CENSUS"} };
return $self;
}
sub fullname {
my $self = shift;
return $self->{FULLNAME};
}
my question is about $self. in both subroutines $self is returned. But
to be used there is no need to do it.
you can call your package like:
my $var = new My_package($value1);
and after that call the value like:
my $output_for_key = $var -> {AGE}; # for example taken one of the key
above.
So, What is the point of return the $self reference?
As a second question, to use a sub on the package, I can do it on the
same way?
$var->my_function($value_to_pass);
or this can not be done unless I use @EXPORT ?
Thanks for your help and your patience.
John
------------------------------
Date: 16 Oct 2003 16:10:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: newbie question about objects
Message-Id: <bmmfsv$ana$1@mamenchi.zrz.TU-Berlin.DE>
John <news2003@wanadoo.es> wrote in comp.lang.perl.misc:
> Dear all,
>
>
> I was reading about perl objects on
> http://www.perldoc.com/perl5.8.0/pod/perltoot.html
>
> and I found:
>
> sub new {
> my $proto = shift;
> my $class = ref($proto) || $proto;
> my $self = {};
> $self->{FULLNAME} = Fullname->new();
> $self->{AGE} = undef;
> $self->{PEERS} = [];
> $self->{"_CENSUS"} = \$Census;
> bless ($self, $class);
> ++ ${ $self->{"_CENSUS"} };
> return $self;
> }
>
> sub fullname {
> my $self = shift;
> return $self->{FULLNAME};
> }
>
>
> my question is about $self. in both subroutines $self is returned. But
> to be used there is no need to do it.
Only the first one, new(), returns the object. It must, because it has
just created it and there is no other way of learning about it.
The fullname() method doesn't return $self, but whatever is stored in
$self for the key "FULLNAME".
> you can call your package like:
Packages aren't called, methods are. In this case, you call the new()
method. Also, where you say "package", saying "class" would be more
accurate. While Perl classes are indeed packages, packages also have
other uses. When it's the home of objects, better call it a class.
> my $var = new My_package($value1);
The definition of new() shows that it doesn't use any parameters. Specifying
$value in the call doesn't have an effect. The call should be
My_package->new();
I have also chosen the arrow syntax for the call. The syntax you are
using, called the indirect object syntax, is less reliable.
> and after that call the value like:
>
> my $output_for_key = $var -> {AGE}; # for example taken one of the key
> above.
Yes, you *can* do that, but if you do, you expose the inner structure of
your object, thus missing the point of OO. The idea is to define accessor
methods for the components of your structure, hiding the concrete
implementation from the user.
> So, What is the point of return the $self reference?
As noted, it doesn't return $self. It does what an accessor is supposed
to do and returns one of the object's member variables, or whatever you
call them.
> As a second question, to use a sub on the package, I can do it on the
> same way?
>
> $var->my_function($value_to_pass);
Have you tried it? What happened?
> or this can not be done unless I use @EXPORT ?
If anything, you'd be using Exporter. @Export is only a small part of
the picture.
But exportation has nothing to do with method invocation, and you don't
need it in an OO module.
Anno
------------------------------
Date: 16 Oct 2003 10:40:04 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: newbie question about objects
Message-Id: <3ee08638.0310160940.49294470@posting.google.com>
news2003@wanadoo.es (John) wrote in message news:<3bd6db81.0310160604.770e84cb@posting.google.com>...
[...]
> ++ ${ $self->{"_CENSUS"} };
> return $self;
> }
>
> sub fullname {
> my $self = shift;
> return $self->{FULLNAME};
> }
>
>
> my question is about $self. in both subroutines $self is returned. But
> to be used there is no need to do it.
In the first, $self is returned. In the second, a member of $self is
returned. This is how object-oriented programming is done. I think
you're getting way ahead of yourself in digging into the OO stuff
before you have a strong handle on the fundamentals. I don't say that
to put you down at all, it's serious advice.
At the very least, try perlboot before you try perltoot.
> you can call your package like:
>
> my $var = new My_package($value1);
But for the assignment to happen, the new() function has to return the
new object, which is $self.
> and after that call the value like:
>
> my $output_for_key = $var -> {AGE}; # for example taken one of the key
That violates the principle of encapsulation in OO programming. You
CAN do it, but then you're not doing OO programming.
> As a second question, to use a sub on the package, I can do it on the
> same way?
>
> $var->my_function($value_to_pass);
>
> or this can not be done unless I use @EXPORT ?
Members are always accessible. Note that perltoot says:
For this module we aren't going to use Exporter, because
we're a well-behaved class module that doesn't export
anything at all.
Exporting is for referring things in another package without
specifying the package. Your object isn't in another package, nor are
its members.
------------------------------
Date: 16 Oct 2003 08:25:58 -0700
From: reneap@hotmail.com (Ren Patterson)
Subject: Re: Perl scripts for Unix on my windows machine
Message-Id: <2e13d330.0310160725.f852d37@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bmlsi7
>
> Oh yes, we've heard that a few times, believe me.
>
> On Usenet, it also matters whom you ask. If you have a question that
> a computer can answer, ask the machine first. Your question could be
> answered by a computer, but you asked the group first. That is
> considered rude.
>
> Anno
Oh yeah wise guy?
What do you say
I send you an exe file, you can not ask me if it is malicious, and say
you don't have a virus detector, I want to see you letting your
computer tell you whether it is a virus or not.
In case you do not get it yet I will repeat, I searched for the answer
and I was not sure if I would cause my computer harm by installing it
and then finding out afterwards. Is that too hard to grasp?
------------------------------
Date: Thu, 16 Oct 2003 16:36:35 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl scripts for Unix on my windows machine
Message-Id: <h6itov0gk1r2af46jtiq3ubu9olr05u4el@4ax.com>
Ren Patterson wrote:
>I have a few perl scripts made for Unix that I would like to use
>either on my windows server or apache on my windows PC if I must
>install apache. Is there a foreknown reason why the Unix scripts would
>not work in these environments? thanks.
Apache checks the shebang line of scripts. That perl executable must
exist. Just a plain "perl" will do.
--
Bart.
------------------------------
Date: Thu, 16 Oct 2003 16:58:31 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perl scripts for Unix on my windows machine
Message-Id: <20031016125830.44f3973a.jwillmore@remove.adelphia.net>
On 16 Oct 2003 08:25:58 -0700
reneap@hotmail.com (Ren Patterson) wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<bmlsi7
> >
> > Oh yes, we've heard that a few times, believe me.
> >
> > On Usenet, it also matters whom you ask. If you have a question
> > that a computer can answer, ask the machine first. Your question
> > could be answered by a computer, but you asked the group first.
> > That is considered rude.
> >
> > Anno
>
> Oh yeah wise guy?
>
> What do you say
> I send you an exe file, you can not ask me if it is malicious, and
> say you don't have a virus detector, I want to see you letting your
> computer tell you whether it is a virus or not.
>
> In case you do not get it yet I will repeat, I searched for the
> answer and I was not sure if I would cause my computer harm by
> installing it and then finding out afterwards. Is that too hard to
> grasp?
The point Anno was making was this:
if you code correctly (meaning, you enable warnings), you will get
your answers.
if you use the documentation, you will get your answers.
Now, after that little bit of anger, why don't you go somewhere, count
to 100, and then post. That direction is included in the FAQ for this
group -and- IMHO, good advise.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
You never know how many friends you have until you rent a house
<on the beach.
------------------------------
Date: 16 Oct 2003 17:48:45 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Strange behaviour with '\r' character [[ sorry my other post was wrong typed ]]
Message-Id: <u9ad81ruvm.fsf@wcl-l.bham.ac.uk>
Anand <some@one.com> rudely writes upside down:
[ Rudeness corrected ]
> Brian McCauley wrote:
>
> > print "\\r is whitespace!\n" if "\r" =~ /^\s$/;
> >
> seems to me that \r is reserved for white space.
What information did you intend to convey by the phrase "reserved
for"?
Apart from inserting that phrase and "seems to me that" you are mearly
repeating what I just said, namely: \r is whitespace.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 16 Oct 2003 13:47:02 GMT
From: Anand <some@one.com>
Subject: Re: Strange behaviour with '\r' character [[ sorry my other post was wrong typed ]]
Message-Id: <qjxjb.2729$8x2.1551200@newssrv26.news.prodigy.com>
seems to me that \r is reserved for white space.
--Anand
Brian McCauley wrote:
> i5513@hotmail.com (i5513) writes:
>
>
>>Hi!. I don't understand ...
>
>
> Try this:
>
> print "\\r is whitespace!\n" if "\r" =~ /^\s$/;
>
> Now do you understand?
>
------------------------------
Date: 16 Oct 2003 07:47:55 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Unexpected alteration of array's content
Message-Id: <3ee08638.0310160647.9c67f37@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bmkji9$3kj$1@mamenchi.zrz.TU-Berlin.DE>...
> Well, that is in the eye of the beholder.
All stylistic decisions are subjective to some degree. There is more
agreement on some things than on others. You could save a keystroke by
using y///c instead of length, but I hope no one would recommend it.
> People get used to the weirdest things
They get used to things they are forced to do repeatedly, and things
they do out of habit because they can't be bothered to find a more
sensible way.
> No blink-effect there, not after a few years of the same.
Of course, this argument doesn't apply to something you said was not
going to be common.
> In one context, the "@{[ ... ]}" construct *is* idiomatic. It is regularly
> used to interpolate arbitrary expressions into strings, as in
>
> print "1 + 2 = @{[ 1 + 2 ]}\n";
The only appeal of this is to the bloody-minded desire to do
everything with interpolation. It could be written more clearly as
print '1 + 2 = ', 1+2, "\n";
or, if the creation of a string were desired,
$str = '1 + 2 = ' . (1 + 2) . "\n";
I don't see anything particularly onerous about either of those, for
writing or for reading. Do you?
I seem to recall (though I don't find the doc) that a document that
introduced the reference interpolation feature also disrecommended
this use of it.
(NB: Uri mentioned the scalar version, but omitted necessary
parentheses:
$ perl -e 'print "1+2=${\1+2}\n"'
1+2=
$ perl -e 'print "1+2=${\(1+2)}\n"'
1+2=3
)
> Another is a fix to a misbehaving map or grep. "Oops, it's changing my
> array! Let's put @{[ ... ]} around it."
This is the best example, but it still smacks of a quick and dirty
fix. You could, of course, use the BLOCK forms of map and grep, then
make and work on copies of $_. Depending on what you're doing, you
might also consider rewriting the grep (especially) as a foreach loop.
If you're making a copy, modifying its elements, and returning some of
them into a new array, then throwing away your scratch copy, it might
be better just to build one new array.
I don't consider @{[...]} to be horrible, just mildly distasteful. It
gets worse depending on the size of the array.
> I mentioned I didn't think it comes up often, but there are uses.
> [snip]
> Why not? Once the blink reflex has worn off, it's a possible alternative.
You seem to be playing both sides of the fence. If it's not going to
come up often, the blink reflex isn't going to wear off. Solutions to
unconventional problems are always going to require an instant of "oh,
that's what he's doing". That's not a bad thing. What is a bad thing,
IMO, is when solutions to common problems require that.
Again, this particular example isn't terribly obfuscated. It's just
not a "best practice" (to borrow a phrase that probably has a high
cringe factor). The mindset that "the most succinct solution is the
one to use" is seductive, and warned against in perlstyle (though
probably not in those words). The most straightforward, legible
solution is the one to use, unless there is some distinct advantage to
a more arcane one.
------------------------------
Date: Thu, 16 Oct 2003 15:19:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <x7smlttdkj.fsf@mail.sysarch.com>
>>>>> "RJ" == Roy Johnson <rjohnson@shell.com> writes:
RJ> I don't consider @{[...]} to be horrible, just mildly distasteful. It
RJ> gets worse depending on the size of the array.
i jumped in the middle of this thread (and i am not going back to the
very beginning) but wouldn't a simple @foo = ( blah ) be enough? if you
have a reference already then @{$ref} is fine. so where would @{[ blah
]} be needed except to interpolate? i see the word 'copy' in the thread
and no reason for using a full anon array and deref. it seems to be a
waste of an extra copy (the anon array is tossed!).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 16 Oct 2003 18:05:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <u91xtdru2w.fsf@wcl-l.bham.ac.uk>
In refernce to..
$str = "1 + 2 = @{[ 1 + 2 ]}\n";
rjohnson@shell.com (Roy Johnson) writes:
> The only appeal of this is to the bloody-minded desire to do
> everything with interpolation. It could be written more clearly as
>
> $str = '1 + 2 = ' . (1 + 2) . "\n";
>
> I don't see anything particularly onerous about either of those, for
> writing or for reading.
I don't see and either one is more or less readble than the
other. Double quotes are not the only interpolatative context. The
@{[...]} really comes into it's own in here-docs.
Some people also like to use qr/@{[ EXPR ]}/ but IMHO that's ugly.
> I seem to recall (though I don't find the doc) that a document that
> introduced the reference interpolation feature also disrecommended
> this use of it.
>
> (NB: Uri mentioned the scalar version, but omitted necessary
> parentheses:
> $ perl -e 'print "1+2=${\1+2}\n"'
> 1+2=
> $ perl -e 'print "1+2=${\(1+2)}\n"'
> 1+2=3
> )
Don't use that! Not only does it lack the symmetric appearance of
@{[...]} but it also could fool people into expecting the expression
1+2 to be evaluated in a scalar context. Hell, it even fooled the FAQ
maintainers for a long time. I've finally convinced them to remove
this disinformation.
> > Another is a fix to a misbehaving map or grep. "Oops, it's changing my
> > array! Let's put @{[ ... ]} around it."
>
> This is the best example,
And is indeed the subject of this thread!
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 16 Oct 2003 22:11:00 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: XSL - 3 lines explaination -IGNORE
Message-Id: <bmmho6$gvi$1@newsreader.mailgate.org>
Extremely sorry for posting to the wrong newgroup.
------------------------------
Date: Thu, 16 Oct 2003 20:10:53 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: XSL - 3 lines explaination
Message-Id: <bmmam2$66m$1@newsreader.mailgate.org>
Below is a XSL that I can barely understand being a newbie to XSL world.
Can someone let me know what do these 3 lines do exactly?
- <xsl:attribute name="MemberKey">
<xsl:number level="multiple"
count="Hierarchy/HierarchyMember|Hierarchy/HierarchyMember/HierarchyMember"
format="-1-1" />
</xsl:attribute>
Also, if you can tell me how I can implement this in VB using DOM (MSXML).
Many Thanks.
Below is "a part of" XSL that I have to decode and understand....:(
- <xsl:choose>
- <xsl:when test="parent::Hierarchy">
<xsl:attribute name="Level">1</xsl:attribute>
- <xsl:attribute name="FullName">
<xsl:value-of select="@MemberName" />
</xsl:attribute>
- <xsl:attribute name="MemberKey">
<xsl:number level="multiple" count="Hierarchy/HierarchyMember"
format="-1"/>
</xsl:attribute>
</xsl:when>
- <xsl:when test="../parent::Hierarchy">
<xsl:attribute name="Level">2</xsl:attribute>
- <xsl:attribute name="FullName">
<xsl:value-of select="../@MemberName" /> >
<xsl:value-of select="@MemberName" />
</xsl:attribute>
- <xsl:attribute name="MemberKey">
<xsl:number level="multiple"
count="Hierarchy/HierarchyMember|Hierarchy/HierarchyMember/HierarchyMember"
format="-1-1" />
</xsl:attribute>
</xsl:when>
- <xsl:when test="../../parent::Hierarchy">
<xsl:attribute name="Level">3</xsl:attribute>
- <xsl:attribute name="FullName">
<xsl:value-of select="../../@MemberName" />
>
<xsl:value-of select="../@MemberName" />
>
<xsl:value-of select="@MemberName" />
</xsl:attribute>
- <xsl:attribute name="MemberKey">
<xsl:number level="multiple"
count="Hierarchy/HierarchyMember|Hierarchy/HierarchyMember/HierarchyMember|H
ierarchy/HierarchyMember/HierarchyMember/HierarchyMember" format="-1-1-1" />
</xsl:attribute>
</xsl:when>
------------------------------
Date: 16 Oct 2003 18:08:26 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: XSL - 3 lines explaination
Message-Id: <u9wub5qfed.fsf@wcl-l.bham.ac.uk>
"Kasp" <kaspREMOVE_CAPS@epatra.com> writes:
> Newsgroups: comp.lang.perl.misc
[ Question about XSL ]
Eh?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 16 Oct 2003 23:15:08 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: XSL - 3 lines explaination
Message-Id: <bmmlf8$m4u$1@newsreader.mailgate.org>
>> Newsgroups: comp.lang.perl.misc
> Eh?
>
Easy Dude....I am sorry about that.
------------------------------
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.
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 V10 Issue 5671
***************************************