[11999] in Perl-Users-Digest
Perl-Users Digest, Issue: 5600 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 7 18:07:30 1999
Date: Fri, 7 May 99 15:01:26 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 7 May 1999 Volume: 8 Number: 5600
Today's topics:
Re: simple way for several if ( eq ||) ? (Bart Lateur)
Re: simple way for several if ( eq ||) ? (Larry Rosler)
Re: simple way for several if ( eq ||) ? <aqumsieh@matrox.com>
Re: Stupid FAQ question of the (day? month? year?) <design@raincloud-studios.com>
Superfluous message with 'system' <marcoj@iro.umontreal.ca>
Re: UNIX comands and switches in perl <ludlow@us.ibm.com>
Re: user-defined regex problem <pvorishatesspam@earthlink.net>
Re: user-defined regex problem <pvorishatesspam@earthlink.net>
Re: using $, (was Re: having problems) (Fuzzy Warm Moogles)
Re: using $, (was Re: having problems) (Bart Lateur)
Re: using $, (was Re: having problems) (Larry Rosler)
Re: Why my? (Andrew Allen)
Re: Why my? <emschwar@rmi.net>
Re: Why my? <design@raincloud-studios.com>
Writing to directory <rmthisyegor@andthisgrn.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 May 1999 19:55:06 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: simple way for several if ( eq ||) ?
Message-Id: <373344e4.4629683@news.skynet.be>
Larry Rosler wrote:
>This Is The Way To Do It.
> my %accept;
> @accept{ qw(BOB SAM CHRIS DAVE) } = ();
> if (exists $accept{$name}) { ... }
The "Way To Do It" is to create the hash once, and then do the test as
many times as you need it.
Bart.
------------------------------
Date: Fri, 7 May 1999 14:10:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: simple way for several if ( eq ||) ?
Message-Id: <MPG.119cf68f8367b9c99899fe@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <373344e4.4629683@news.skynet.be> on Fri, 07 May 1999
19:55:06 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Larry Rosler wrote:
>
> >This Is The Way To Do It.
>
> > my %accept;
> > @accept{ qw(BOB SAM CHRIS DAVE) } = ();
> > if (exists $accept{$name}) { ... }
>
>
> The "Way To Do It" is to create the hash once, and then do the test as
> many times as you need it.
That was implicit. And that's how it was done in Bob Trieger's
benchmark that I referred to in the same post.
If you're not going to do the test over and over, then creating the hash
is dumb. Just loop over the list.
perlfaq4: "How can I tell whether a list or array contains a certain
element?"
... 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 keep an associative array lying about whose keys are the first
array's values.
@blues = qw/azure cerulean teal turquoise lapis-lazuli/;
undef %is_blue;
for (@blues) { $is_blue{$_} = 1 }
Gosh. It says 'associative array' instead of 'hash', and it uses a loop
instead of a hash slice. TomC: time for an upgrade???
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 7 May 1999 15:11:40 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: simple way for several if ( eq ||) ?
Message-Id: <x3yd80cy9sl.fsf@tigre.matrox.com>
sam@godzilla.wvn.wvnet.edu writes:
> Hi All Is there a simpler way to do the following:
>
> if ($name eq "BOB" || $name eq "SAM" || $name eq "CHRIS" || $name eq "DAVE"){}
My favourite would be:
my %names = qw/BOB 1 SAM 1 CHRIS 1 DAVE 1/;
if (exists $names{uc $name}) { .. }
But it depends on how much memory you're willing to sacrifice. You can
also do something like:
my @names = qw/BOB SAM CHRIS DAVE/;
if (is_in($name, @names)) { .. }
sub is_in {
my $name = shift;
for my $n (@_) {
return 1 if $n eq uc $name;
}
}
Which is a bit slower, but consumes less memory.
HTH,
Ala
------------------------------
Date: Fri, 07 May 1999 20:04:42 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Stupid FAQ question of the (day? month? year?)
Message-Id: <uHHY2.285$vP2.176@news.rdc1.tn.home.com>
>A simple text editor, such as notepad, is a lot less cumbersome than a
>web-browser. I can have my answer by the time the browser initializes.
>
>I don't know about the MS version of perl, but the GS 5.004 version
>already saves them as html. I use these also if I already have a browser
>window open.
Guess it all depends on your working method. I develop on a Linux but have a
Win machine right next to it watching the NGs with a browser open to perl.com
and one open to my local FAQ. It beats flipping about on either system.
CT
------------------------------
Date: Fri, 07 May 1999 20:15:44 GMT
From: "Marco Jacques" <marcoj@iro.umontreal.ca>
Subject: Superfluous message with 'system'
Message-Id: <QRHY2.492$I51.46189@carnaval.risq.qc.ca>
I have a superfluous message when I'm using the 'system' function under
Windows98. The message says : 'Invalid switch', even if the command is
executed correctly. Is there a bug in the Perl distribution that I am
using (ActivePerl, version 5.004_02) ?
Thanks in advance,
Marco
------------------------------
Date: Fri, 07 May 1999 14:55:02 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: UNIX comands and switches in perl
Message-Id: <37334516.B334835@us.ibm.com>
Jerry Raynor
>
> I'm not familiar with doing that. I have no problem figuring it out for
> myself but where can I get perlop manpages? (sorry if this sounds stuppid
> but I haven't had to search for detailed info until now). Thanks for your
> help!
When people (myself included) have been telling you to read various
pieces of documentation, like 'perldoc perlre', we're giving you both
the "what" to read and the "how" to read it.
perldoc is a program that will display Perl documentation. perlre,
perlop, etc. are pieces of the documentation that you want to read. So
at the command line (shell prompt) just type 'perldoc perlre' and you're
in business. You should start with 'perldoc perldoc' to familiarize
yourself with it.
You can also get all of the documentation online at www.perl.com.
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Fri, 07 May 1999 13:13:23 -0700
From: Phil Voris <pvorishatesspam@earthlink.net>
Subject: Re: user-defined regex problem
Message-Id: <37334963.2E11A463@earthlink.net>
interesting point with the /e. I had actually just finished modifying
it to use /e as follows:
if ($regex_flag) {
# -rie
if ($case_flag && $exec_flag) {
eval "\$number = \$file_contents =~ s/$old/$new/gie";
}
# -ri
if ($case_flag && !$exec_flag) {
eval "\$number = \$file_contents =~ s/$old/$new/gi";
}
# -re
if ($exec_flag && !$case_flag) {
eval "\$number = \$file_contents =~ s/$old/$new/ge";
}
# -r
if (!$exec_flag && !$case_flag) {
eval "\$number = \$file_contents =~ s/$old/$new/g";
}
}
# NON-REGEX SUBSTITUTION
# convert $old and $new if not $regex_flag
# this removes any special regex character functionality
else {
$old = quotemeta ($old);
$new = quotemeta ($new);
eval "\$number = \$file_contents =~ s/$old/$new/g";
}
I guess the /e issue isn't too problematic insofar as this is a local
tool, not something one would interface to a CGI (well, I wouldn't, but
who knows about other folks ...). I guess there's a case for doing a
regex check against the $new and $old strings for things like backticks
and system calls.
------------------------------
Date: Fri, 07 May 1999 13:17:19 -0700
From: Phil Voris <pvorishatesspam@earthlink.net>
Subject: Re: user-defined regex problem
Message-Id: <37334A4F.CEE99132@earthlink.net>
Maybe it's a situation in which I should use Safe. *research,
research....* :)
------------------------------
Date: Fri, 07 May 1999 20:31:56 GMT
From: tgy@chocobo.org (Fuzzy Warm Moogles)
Subject: Re: using $, (was Re: having problems)
Message-Id: <37364d84.6737173@news.oz.net>
On Fri, 07 May 1999 18:47:40 GMT, bart.lateur@skynet.be (Bart Lateur) wrote:
>I mean that different array ELEMENTS have different sizes. Your and
>Larry's arrays have elements with ALL the same constant size.
>
>Apparently that makes a difference.
Random sizes would be more realistic, but I don't see how it would make a
difference. It didn't when I tried it.
>Anyway, it shows once more that the benchmarks are not that reliable,
>because they vary across Perl versions and data size, so relatively
>small differences may safely be discarded. Let's go only for readabilty,
>however you define it.
This is unlikely a bottleneck, so benchmarks are better applied elsewhere.
As for readability, I like your version when print() is used several times
but Uri's when it is done once.
--
Fuzzy | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: Fri, 07 May 1999 20:58:53 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: using $, (was Re: having problems)
Message-Id: <373a538e.8384191@news.skynet.be>
Fuzzy Warm Moogles wrote:
>Random sizes would be more realistic, but I don't see how it would make a
>difference. It didn't when I tried it.
Hmm... It did for me. I got different relative results every time I
tried it.
Maybe the delay is the effect of the disk buffering. We should recreate
the file for every benchmark. Now we're appending to the result of the
previous test.
Bart.
------------------------------
Date: Fri, 7 May 1999 14:38:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: using $, (was Re: having problems)
Message-Id: <MPG.119cfd377bcbe6e4989a01@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <373a538e.8384191@news.skynet.be> on Fri, 07 May 1999
20:58:53 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Hmm... It did for me. I got different relative results every time I
> tried it.
>
> Maybe the delay is the effect of the disk buffering. We should recreate
> the file for every benchmark. Now we're appending to the result of the
> previous test.
Did this drop out of your copy of my benchmark? Writing to a real file
adds system overhead and variance.
open OUT, '>NUL' or die "Couldn't open 'NUL'. $!";
# Pardon my misspelling of '/dev/null'. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 7 May 1999 20:17:31 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Why my?
Message-Id: <7gvhor$ack$2@fcnews.fc.hp.com>
Eric The Read (emschwar@rmi.net) wrote:
: "Gabe" <grichard@uci.edu> writes:
: > OK, so suppose I've got a variable in one part of my program that I want to
: > be available somewhere else, in this case should I not use "my" (and the
: > variable becomes global?)
: You should "use vars qw($var1, @var2, %var3);".
Umm.. drop the commas there.
Andrew
------------------------------
Date: 07 May 1999 14:29:33 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Why my?
Message-Id: <xkfu2tok4ia.fsf@valdemar.col.hp.com>
ada@fc.hp.com (Andrew Allen) writes:
> Eric The Read (emschwar@rmi.net) wrote:
> : You should "use vars qw($var1, @var2, %var3);".
>
> Umm.. drop the commas there.
Duh, I always do that. -w always catches it for me, but it seems like
nearly every time I use qw, I end up putting commas in between the
items. This is why I always use -w and use strict. :)
I think I'll go home and write out "I will NOT use commas in qw lists"
1000 times, or something. Sheesh.
-=Eric
------------------------------
Date: Fri, 07 May 1999 20:57:22 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Why my?
Message-Id: <SsIY2.290$vP2.167@news.rdc1.tn.home.com>
>I think I'll go home and write out "I will NOT use commas in qw lists"
>1000 times, or something. Sheesh.
You'll just end up doing it with a loop. Admit it! :)
CT
------------------------------
Date: Fri, 7 May 1999 16:31:11 -0400
From: "YDS" <rmthisyegor@andthisgrn.com>
Subject: Writing to directory
Message-Id: <7gvi80$73t@dfw-ixnews8.ix.netcom.com>
What would be the way to write a file into directory tree under "nobody"
environment.
As I see, there are two alternative (equally poor in some sense):
1) make the directory tree nobody writable
2) have SUID script executed
Talking about second options it looks like PERL SUID scripts cannot switch the
directory due to some security constraints. My question is how to make SUID perl
program executed in HTTPD environment write to the directory other than local
one?
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5600
**************************************