[26420] in Perl-Users-Digest
Perl-Users Digest, Issue: 8590 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 1 00:10:38 2005
Date: Mon, 31 Oct 2005 21:10:30 -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, 31 Oct 2005 Volume: 10 Number: 8590
Today's topics:
OO Perl, iterators <nobody@bigpond.com>
Re: OO Perl, iterators (Anno Siegel)
Re: OO Perl, iterators <nobody@bigpond.com>
Re: OO Perl, iterators (Anno Siegel)
Re: OO Perl, iterators <1usa@llenroc.ude.invalid>
Re: OO Perl, iterators <tadmc@augustmail.com>
Re: OO Perl, iterators (Anno Siegel)
Re: OO Perl, iterators (Anno Siegel)
Re: OO Perl, iterators <rvtol+news@isolution.nl>
Perl gethostbyname x@y.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 31 Oct 2005 09:18:56 GMT
From: Gregory Toomey <nobody@bigpond.com>
Subject: OO Perl, iterators
Message-Id: <4365e17f@news.comindico.com.au>
I'm a bit confused about the Perl OO syntax. From my reading "foreach" acts
as an iterator.
Any somebody tell me in the standard example below:
- how to count the total number of $query->answer
- how to access the i'th answer; $query->answer[$i] does not work
- how to access a random answer
thanks
gtoomey
--
use Net::DNS;
my $res = Net::DNS::Resolver->new;
my $query = $res->query("example.com", "NS");
if ($query) {
foreach $rr (grep { $_->type eq 'NS' } $query->answer) {
print $rr->nsdname, "\n";
}
}
------------------------------
Date: 31 Oct 2005 10:36:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OO Perl, iterators
Message-Id: <dk4s2t$e6r$1@mamenchi.zrz.TU-Berlin.DE>
Gregory Toomey <nobody@bigpond.com> wrote in comp.lang.perl.misc:
> I'm a bit confused about the Perl OO syntax. From my reading "foreach" acts
> as an iterator.
It is a loop construct. An iterator is something that produces
values to iterate over, like <> or "each" in Perl.
> Any somebody tell me in the standard example below:
For all of these, do
my @answers = $query->answer;
> - how to count the total number of $query->answer
my $total = @answers;
> - how to access the i'th answer; $query->answer[$i] does not work
my $i_th = @answers[ $i];
> - how to access a random answer
my $rand_ans = @answers[ rand @answers];
> thanks
> gtoomey
> --
> use Net::DNS;
> my $res = Net::DNS::Resolver->new;
> my $query = $res->query("example.com", "NS");
>
> if ($query) {
> foreach $rr (grep { $_->type eq 'NS' } $query->answer) {
^^^
You're not running under strict! You've been around long enough to
know better.
> print $rr->nsdname, "\n";
> }
> }
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Mon, 31 Oct 2005 11:40:02 GMT
From: Gregory Toomey <nobody@bigpond.com>
Subject: Re: OO Perl, iterators
Message-Id: <43660291@news.comindico.com.au>
Anno Siegel wrote:
> Gregory Toomey <nobody@bigpond.com> wrote in comp.lang.perl.misc:
>> I'm a bit confused about the Perl OO syntax. From my reading "foreach"
>> acts as an iterator.
>
> It is a loop construct. An iterator is something that produces
> values to iterate over, like <> or "each" in Perl.
>
>> Any somebody tell me in the standard example below:
>
> For all of these, do
>
> my @answers = $query->answer;
>
>
>> - how to count the total number of $query->answer
>
> my $total = @answers;
>
>> - how to access the i'th answer; $query->answer[$i] does not work
>
> my $i_th = @answers[ $i];
>
>> - how to access a random answer
>
> my $rand_ans = @answers[ rand @answers];
>
>> thanks
>> gtoomey
>> --
>> use Net::DNS;
>> my $res = Net::DNS::Resolver->new;
>> my $query = $res->query("example.com", "NS");
>>
>> if ($query) {
>> foreach $rr (grep { $_->type eq 'NS' } $query->answer) {
> ^^^
> You're not running under strict! You've been around long enough to
> know better.
>
>> print $rr->nsdname, "\n";
>> }
>> }
>
> Anno
That code was from the NET::DNS module.
I think I found the answer to my original question.
The syntax $query->answer[$i] is wrong; ($query->answer)[$i] works even
though it looks strange.
gtoomey
------------------------------
Date: 31 Oct 2005 11:48:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OO Perl, iterators
Message-Id: <dk50a9$gv5$1@mamenchi.zrz.TU-Berlin.DE>
Gregory Toomey <nobody@bigpond.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Gregory Toomey <nobody@bigpond.com> wrote in comp.lang.perl.misc:
> >> I'm a bit confused about the Perl OO syntax. From my reading "foreach"
> >> acts as an iterator.
> >
> > It is a loop construct. An iterator is something that produces
> > values to iterate over, like <> or "each" in Perl.
> >
> >> Any somebody tell me in the standard example below:
> >
> > For all of these, do
> >
> > my @answers = $query->answer;
> >
> >
> >> - how to count the total number of $query->answer
> >
> > my $total = @answers;
> >
> >> - how to access the i'th answer; $query->answer[$i] does not work
> >
> > my $i_th = @answers[ $i];
> >
> >> - how to access a random answer
> >
> > my $rand_ans = @answers[ rand @answers];
> >
> >> thanks
> >> gtoomey
> >> --
> >> use Net::DNS;
> >> my $res = Net::DNS::Resolver->new;
> >> my $query = $res->query("example.com", "NS");
> >>
> >> if ($query) {
> >> foreach $rr (grep { $_->type eq 'NS' } $query->answer) {
> > ^^^
> > You're not running under strict! You've been around long enough to
> > know better.
> >
> >> print $rr->nsdname, "\n";
> >> }
> >> }
> >
> > Anno
>
> That code was from the NET::DNS module.
So? You are responsible for the code you post, even if you take it from
somewhere else.
> I think I found the answer to my original question.
> The syntax $query->answer[$i] is wrong; ($query->answer)[$i] works even
> though it looks strange.
It's a normal list slice, nothing strange about it. However, it
will calculate the entire list of answers each time you want to
extract a single element. Caching the list, as in my code above,
avoids that.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Mon, 31 Oct 2005 12:41:46 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: OO Perl, iterators
Message-Id: <Xns97004E4B2FD25asu1cornelledu@127.0.0.1>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:dk4s2t$e6r$1@mamenchi.zrz.TU-Berlin.DE:
> my $i_th = @answers[ $i];
Just a quick correction: @answers[$i] is an array slice; ITYM:
my $i_th = $answers[ $i];
;-)
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Mon, 31 Oct 2005 06:03:59 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: OO Perl, iterators
Message-Id: <slrndmc21f.5do.tadmc@magna.augustmail.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> - how to access the i'th answer; $query->answer[$i] does not work
>
> my $i_th = @answers[ $i];
^
^
my $i_th = $answers[ $i];
>> - how to access a random answer
>
> my $rand_ans = @answers[ rand @answers];
^
^
my $rand_ans = $answers[ rand @answers];
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 31 Oct 2005 13:36:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OO Perl, iterators
Message-Id: <dk56kb$qlo$1@mamenchi.zrz.TU-Berlin.DE>
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> >> - how to access the i'th answer; $query->answer[$i] does not work
> >
> > my $i_th = @answers[ $i];
> ^
> ^
>
> my $i_th = $answers[ $i];
>
>
> >> - how to access a random answer
> >
> > my $rand_ans = @answers[ rand @answers];
> ^
> ^
>
> my $rand_ans = $answers[ rand @answers];
Oh dear, yes!
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 31 Oct 2005 13:42:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: OO Perl, iterators
Message-Id: <dk570o$qlo$2@mamenchi.zrz.TU-Berlin.DE>
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
> news:dk4s2t$e6r$1@mamenchi.zrz.TU-Berlin.DE:
>
> > my $i_th = @answers[ $i];
>
> Just a quick correction: @answers[$i] is an array slice; ITYM:
>
> my $i_th = $answers[ $i];
Oh, that too... Same mistake as with the random element you mercifully
snipped. I was thinking Perl 6[1], that's my excuse.
Anno
[1] Though I don't understand how Larry can say Perl 6 is still going
to be Perl when the variables don't change their sigils like a
chameleon (ha!) its colors.
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Mon, 31 Oct 2005 15:23:48 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: OO Perl, iterators
Message-Id: <dk5cu9.3js.1@news.isolution.nl>
Anno Siegel:
> I was thinking Perl 6
I was thinking that you were thinking Perl 6.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Tue, 01 Nov 2005 10:47:10 +1100
From: x@y.com
Subject: Perl gethostbyname
Message-Id: <4366acf3$0$20444$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
I'm trying to get Perl 5.8.7 working on z/OS. This nearly works but...
for some reason the inet_aton and gethostbyname calls are returning undef.
I guess that this means that I have to get involved in debugging the
internals. Does anyone know what C files lie at the heart of these
routines and what the best way to go about patching them is?
Ross
------------------------------
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 V10 Issue 8590
***************************************