[26268] in Perl-Users-Digest
Perl-Users Digest, Issue: 8451 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 24 14:05:33 2005
Date: Sat, 24 Sep 2005 11:05: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, 24 Sep 2005 Volume: 10 Number: 8451
Today's topics:
Re: FAQ 4.42 How can I tell whether a certain element i (Anno Siegel)
Re: FAQ 4.42 How can I tell whether a certain element i <john@castleamber.com>
Re: FAQ 4.42 How can I tell whether a certain element i (Anno Siegel)
Re: new how-to book about tit-fucking <misterlister169@gmail.com>
Re: new how-to book about tit-fucking <monkie@postmaster.co.uk>
Re: new how-to book about tit-fucking <misterlister169@gmail.com>
Re: new how-to book about tit-fucking <eat@theY.cum >
Order of Elements in Hash <laststop@cwnet.com>
Re: Order of Elements in Hash (Jay Tilton)
problem with perldoc <tosoAplos@earth.space>
Re: problem with perldoc <steve@uptime.org.uk>
Re: problem with perldoc <tosoAplos@earth.space>
Re: problem with perldoc <sherm@dot-app.org>
Re: problem with perldoc <tosoAplos@earth.space>
Re: regex, number of matches <tadmc@augustmail.com>
Re: regex, number of matches <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Sep 2005 15:49:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <dh3shf$p56$1@mamenchi.zrz.TU-Berlin.DE>
PerlFAQ Server <comdog@panix.com> wrote in comp.lang.perl.misc:
This is essentially a re-post of my FAQ suggestion in the thread "scalar
and hash slices -- is it supposed to work this way?".
> This message is one of several periodic postings to comp.lang.perl.misc
> intended to make it easier for perl programmers to find answers to
> common questions. The core of this message represents an excerpt
> from the documentation provided with Perl.
>
> --------------------------------------------------------------------
>
> 4.42: How can I tell whether a certain element is contained in a list or array?
>
> Hearing the word "in" is an *in*dication that you probably should have
> used a hash, not a list or array, to store your data. Hashes are
> designed to answer this question quickly and efficiently. Arrays aren't.
>
> That being said, there are several ways to approach this. If you are
> going to make this query many times over arbitrary string values, the
> fastest way is probably to invert the original array and maintain a hash
> whose keys are the first array's values.
>
> @blues = qw/azure cerulean teal turquoise lapis-lazuli/;
> %is_blue = ();
> for (@blues) { $is_blue{$_} = 1 }
>
> Now you can check whether $is_blue{$some_color}. It might have been a
> good idea to keep the blues all in a hash in the first place.
>
> If the values are all small integers, you could use a simple indexed
> array. This kind of an array will take up less space:
>
> @primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31);
> @is_tiny_prime = ();
> for (@primes) { $is_tiny_prime[$_] = 1 }
> # or simply @istiny_prime[@primes] = (1) x @primes;
>
> Now you check whether $is_tiny_prime[$some_number].
>
> If the values in question are integers instead of strings, you can save
> quite a lot of space by using bit strings instead:
>
> @articles = ( 1..10, 150..2000, 2017 );
> undef $read;
> for (@articles) { vec($read,$_,1) = 1 }
>
> Now check whether "vec($read,$n,1)" is true for some $n.
From here, I'd replace the text with what follows below.
> Please do not use
>
> ($is_there) = grep $_ eq $whatever, @array;
>
> or worse yet
>
> ($is_there) = grep /$whatever/, @array;
>
> These are slow (checks every element even if the first matches),
> inefficient (same reason), and potentially buggy (what if there are
> regex characters in $whatever?). If you're only testing once, then use:
>
> $is_there = 0;
> foreach $elt (@array) {
> if ($elt eq $elt_to_find) {
> $is_there = 1;
> last;
> }
> }
> if ($is_there) { ... }
Replace with:
These methods guarantee fast individual tests but require a re-organization
of the original list or array. They only pay off if you have to test
multiple values against the same array.
If you are testing only once, the standard module List::Util exports
the function C<first> for this purpose. It works like
sub first (&@) {
my $code = shift;
foreach (@_) {
return $_ if &{$code}();
}
undef;
}
but has a fast implementation in C.
If speed is of little concern, the common idiom is
($is_there) = grep $_ eq $whatever, @array;
It is slow (checks every element even if the first matches), but simple and
flexible. The variant
($first, @others) = grep $_ eq $whatever, @array;
allows to tell whether the match was unique.
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: 24 Sep 2005 16:08:51 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <Xns96DB70DDDCDC3castleamber@130.133.1.4>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> PerlFAQ Server <comdog@panix.com> wrote in comp.lang.perl.misc:
>
> This is essentially a re-post of my FAQ suggestion in the thread
> "scalar and hash slices -- is it supposed to work this way?".
Can't the FAQ be edited using a wiki or something like that? I mean, aren't
we programmers :-D.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 24 Sep 2005 17:37:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <dh42ss$s9k$1@mamenchi.zrz.TU-Berlin.DE>
John Bokma <john@castleamber.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> > PerlFAQ Server <comdog@panix.com> wrote in comp.lang.perl.misc:
> >
> > This is essentially a re-post of my FAQ suggestion in the thread
> > "scalar and hash slices -- is it supposed to work this way?".
>
> Can't the FAQ be edited using a wiki or something like that? I mean, aren't
> we programmers :-D.
I'm sure it can and yes, some of us are. So far, no one was sufficiently
motivated to make the preliminary contacts and, perhaps, write such a
thing. So what?
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: Sat, 24 Sep 2005 12:24:23 +0100
From: Lister <misterlister169@gmail.com>
Subject: Re: new how-to book about tit-fucking
Message-Id: <rndaj1h894bthg6hloif75i5jmp4faql73@4ax.com>
On 23 Sep 2005 19:33:02 -0400, Robert de Vincy <rxdxv@talk21.com>
wrote:
>Lister did write:
>
>> From: Lister <misterlister169@gmail.com>
>
>I refuse to believe there are at least 168 other "misterlister"
>gmail addresses.
muhh, no, 169 is Dave Lister's number on Red Dwarf
--
.sig for rent
Apply within
------------------------------
Date: Sat, 24 Sep 2005 13:22:51 +0100
From: monkie <monkie@postmaster.co.uk>
Subject: Re: new how-to book about tit-fucking
Message-Id: <dh3geo$abo$3@news.freedom2surf.net>
Lister wrote:
> On 23 Sep 2005 19:33:02 -0400, Robert de Vincy <rxdxv@talk21.com>
> wrote:
>
>
>>Lister did write:
>>
>>
>>>From: Lister <misterlister169@gmail.com>
>>
>>I refuse to believe there are at least 168 other "misterlister"
>>gmail addresses.
>
>
>
> muhh, no, 169 is Dave Lister's number on Red Dwarf
>
there are 169 lister169-<random_number>@gmail.com though.
--
-monkie-
"For Fuck’s Sake Nintendo…" -Fort90
www.commando-destruction.com
------------------------------
Date: Sat, 24 Sep 2005 14:29:16 +0100
From: Lister <misterlister169@gmail.com>
Subject: Re: new how-to book about tit-fucking
Message-Id: <15laj1dog5ajrdfb91pf6ho11m2vor3rs2@4ax.com>
On Sat, 24 Sep 2005 13:22:51 +0100, monkie <monkie@postmaster.co.uk>
wrote:
>Lister wrote:
>> On 23 Sep 2005 19:33:02 -0400, Robert de Vincy <rxdxv@talk21.com>
>> wrote:
>>
>>
>>>Lister did write:
>>>
>>>
>>>>From: Lister <misterlister169@gmail.com>
>>>
>>>I refuse to believe there are at least 168 other "misterlister"
>>>gmail addresses.
>>
>>
>>
>> muhh, no, 169 is Dave Lister's number on Red Dwarf
>>
>
>there are 169 lister169-<random_number>@gmail.com though.
Probably
--
.sig for rent
Apply within
------------------------------
Date: Sat, 24 Sep 2005 16:56:50 GMT
From: projectile vomit chick <eat@theY.cum >
Subject: Re: new how-to book about tit-fucking
Message-Id: <5a1bj1ldpjs1u27a6esfb5q540r08tl0ap@4ax.com>
On Fri, 23 Sep 2005 23:31:01 +0100, in alt.drugs.hard, Lister
<misterlister169@gmail.com> hit the crackpipe and declared:
>On Fri, 27 May 2005 21:50:46 +0200 (CEST), "Agent 69"
><69-no-spam@69.69.69.69.invalid> wrote:
>
>
>
>
>Titfucking for dummies?
Oil 'em up and bring 'em over
--
Keep it simple. One day at a time. Easy does it. Let go and
let God. Hugs not drugs. No more stinking thinking. Turn it over.
And if all else fails, look on the bright side, suicide.
------------------------------
Date: Sat, 24 Sep 2005 06:01:42 -0700
From: laststop <laststop@cwnet.com>
Subject: Order of Elements in Hash
Message-Id: <11jajhlg61j5l37@corp.supernews.com>
I know the order of elements in a hash cannot be relied upon - but can I
rely on the relative order of keys to values, i.e.
given:
%x = (one => 1, two => 2, three => 3);
if
join(' ',keys %x)
yields:
two three one
can I be sure that
join(' ',values %x)
yields:
2 3 1
presuming %x is not modified between calls.
Thanks
http://bros.sixbit.org/glyco
------------------------------
Date: Sat, 24 Sep 2005 13:09:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Order of Elements in Hash
Message-Id: <43354f29.293391424@news.rcn.com>
laststop <laststop@cwnet.com> wrote:
: I know the order of elements in a hash cannot be relied upon - but can I
: rely on the relative order of keys to values, i.e.
Yes, as "perldoc -f keys" or "perldoc -f values" clearly states with its
bold use of the word "guaranteed."
Do you frequently use functions without reading their documentation?
------------------------------
Date: Sat, 24 Sep 2005 16:17:44 +0000 (UTC)
From: "Apostolos P. Tsompanopoulos" <tosoAplos@earth.space>
Subject: problem with perldoc
Message-Id: <dh3u78$du8$1@ulysses.noc.ntua.gr>
I have the following situation and I'm asking for some hint...
$ perldoc perls<TAB><TAB>
perlsec perlsolaris perlstyle perlsub perlsyn
$ perldoc perlsec
No documentation found for "perlsec".
$ perldoc perlsub
No documentation found for "perlsub".
Although when pressing the <TAB> twice I'm getting some choices, when I
ask the documentation for something more specific, I'm getting nothing!
Any hint on where to look to correct this?
TIA,
Apostolos
--
Replace earth.space with gmail.com for a valid e-mail
------------------------------
Date: Sat, 24 Sep 2005 17:21:27 +0100
From: Stephen Hildrey <steve@uptime.org.uk>
Subject: Re: problem with perldoc
Message-Id: <1127578887.17298.0@ersa.uk.clara.net>
Apostolos P. Tsompanopoulos wrote:
> I have the following situation and I'm asking for some hint...
>
> $ perldoc perls<TAB><TAB>
> perlsec perlsolaris perlstyle perlsub perlsyn
> $ perldoc perlsec
> No documentation found for "perlsec".
> $ perldoc perlsub
> No documentation found for "perlsub".
>
> Although when pressing the <TAB> twice I'm getting some choices, when I
> ask the documentation for something more specific, I'm getting nothing!
>
> Any hint on where to look to correct this?
What shell are you using? I can only think that it's a discrepancy
between the environment of your shell's tab completion engine and that
of perldoc.
When I do perldoc perls<tab><tab> (in zsh) - everything that it lists is
present and "findable by" perldoc.
Steve
--
Stephen Hildrey
E-mail: steve@uptime.org.uk / Tel: +442071931337
Jabber: steve@jabber.earth.li / MSN: foo@hotmail.co.uk
------------------------------
Date: Sat, 24 Sep 2005 16:55:04 +0000 (UTC)
From: "Apostolos P. Tsompanopoulos" <tosoAplos@earth.space>
Subject: Re: problem with perldoc
Message-Id: <dh40d8$lcs$1@ulysses.noc.ntua.gr>
On Óáâ, 24 Óåð 2005 at 16:21 GMT, Stephen Hildrey wrote:
> Apostolos P. Tsompanopoulos wrote:
>> I have the following situation and I'm asking for some hint...
>>
>> $ perldoc perls<TAB><TAB>
>> perlsec perlsolaris perlstyle perlsub perlsyn
>> $ perldoc perlsec
>> No documentation found for "perlsec".
>> $ perldoc perlsub
>> No documentation found for "perlsub".
>>
>> Although when pressing the <TAB> twice I'm getting some choices, when I
>> ask the documentation for something more specific, I'm getting nothing!
>>
>> Any hint on where to look to correct this?
>
> What shell are you using? I can only think that it's a discrepancy
> between the environment of your shell's tab completion engine and that
> of perldoc.
>
> When I do perldoc perls<tab><tab> (in zsh) - everything that it lists is
> present and "findable by" perldoc.
>
> Steve
Thank you Steve for your answer...
I'm using bash.
But I've found that:
1. `man perlsec` is working, while `perldoc perlsec` doesn't
2. the perlsec.pod is in /usr/lib/perl5/5.8.1/pod/perlsec.pod and I
have perl version 5.8.3
As you said, it must be a misconfiguration and perldoc doesn't know
where to look for pod files (except for 5.8.3).
(after some thought and some reading of the man page of perldoc)
I've found it! All I had to do was:
export PERL5LIB="/usr/lib/perl5/5.8.3/pod:/usr/lib/perl5/5.8.1/pod"
Apostolos
--
Replace earth.space with gmail.com for a valid e-mail
------------------------------
Date: Sat, 24 Sep 2005 13:11:47 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: problem with perldoc
Message-Id: <m2d5myz8z0.fsf@Sherm-Pendleys-Computer.local>
"Apostolos P. Tsompanopoulos" <tosoAplos@earth.space> writes:
> I have the following situation and I'm asking for some hint...
>
> $ perldoc perls<TAB><TAB>
> perlsec perlsolaris perlstyle perlsub perlsyn
> $ perldoc perlsec
> No documentation found for "perlsec".
> $ perldoc perlsub
> No documentation found for "perlsub".
>
> Although when pressing the <TAB> twice I'm getting some choices, when I
> ask the documentation for something more specific, I'm getting nothing!
>
> Any hint on where to look to correct this?
Do you have multiple Perls installed? Perhaps one Perl is specified in the
perldoc script's #! line, but the shell is finding pods for another one.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sat, 24 Sep 2005 17:55:46 +0000 (UTC)
From: "Apostolos P. Tsompanopoulos" <tosoAplos@earth.space>
Subject: Re: problem with perldoc
Message-Id: <dh43v2$10mo$1@ulysses.noc.ntua.gr>
On Óáâ, 24 Óåð 2005 at 17:11 GMT, Sherm Pendley wrote:
> "Apostolos P. Tsompanopoulos" <tosoAplos@earth.space> writes:
>
>> I have the following situation and I'm asking for some hint...
>>
>> $ perldoc perls<TAB><TAB>
>> perlsec perlsolaris perlstyle perlsub perlsyn
>> $ perldoc perlsec
>> No documentation found for "perlsec".
>> $ perldoc perlsub
>> No documentation found for "perlsub".
>>
>> Although when pressing the <TAB> twice I'm getting some choices, when I
>> ask the documentation for something more specific, I'm getting nothing!
>>
>> Any hint on where to look to correct this?
>
> Do you have multiple Perls installed? Perhaps one Perl is specified in the
> perldoc script's #! line, but the shell is finding pods for another one.
>
> sherm--
Ehmmm... actually no... I have only v5.8.3 installed *BUT* (maybe
during the upgrade) I probably forgot to upgrade perl-doc(s), which
is v5.8.1
I've already solved my problem (see my other message), but I'll look
also to the direction of upgrading my perl-doc!
Thank you,
Apostolos
--
Replace earth.space with gmail.com for a valid e-mail
.
HELLAS is on the final of Eurobasket 2005! ;-)
We're the first in Europe (again)!!!
------------------------------
Date: Sat, 24 Sep 2005 08:01:29 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex, number of matches
Message-Id: <slrndjajh9.s3v.tadmc@magna.augustmail.com>
Dr.Ruud <rvtol+news@isolution.nl> wrote:
> Abigail schreef:
>> Dr.Ruud:
>
>> {} As Abigail showed, there will be a difference between
>> {}
>> {} (1) s/$kw/$kw/g (add \Q and \E where needed)
>> {}
>> {} and
>> {}
>> {} (2) s/\S+/$&/g
>> {}
>> {} and
>> {}
>> {} (3) s/\S+//g
>> and I do not know what you mean by (1) and (3)
>> being "more constant" and hence needing less cycles.
>
> How little the regex changes for each iteration.
The regex *never* changes for (2) and (3), so surely they
must be "more constant"?
> The "$&" part varies in each iteration,
The "$&" part is not in the regular expression portion of s///,
it is in the replacement (double-quotish) _string_ portion.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 24 Sep 2005 08:20:08 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex, number of matches
Message-Id: <slrndjakk8.s3v.tadmc@magna.augustmail.com>
Dr.Ruud <rvtol+news@isolution.nl> wrote:
> I find it hard to think of a reason why the first use of $& should harm
> all other pattern matches.
Because a whole bunch of characters must be stored for
every (successful) pattern match.
> And then why ()/$1 doesn't.
Because a whole bunch of characters must be stored only for
the (successful) pattern matches that explicitly mention them.
One makes a lot of work for every pattern match, the other makes a
lot of work for only some pattern matches.
Optimizing away for "every" has to be a bigger win than opitimizing
away only for "some".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 8451
***************************************