[18714] in Perl-Users-Digest
Perl-Users Digest, Issue: 882 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 12 09:05:41 2001
Date: Sat, 12 May 2001 06:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989672710-v10-i882@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 12 May 2001 Volume: 10 Number: 882
Today's topics:
ANNOUNCE: DBD::Chart 0.40 available <darnold@earthlink.net>
Re: basic TRUE / FALSE (Rudolf Polzer)
Re: finding all uses of a file or module at runtime nobull@mail.com
Re: Forcing default filename (Didier & Olivier Guillion)
Re: Forcing default filename (Andrew Clover)
Re: Forcing default filename (Rudolf Polzer)
Help <scott.bell1@ntlworld.com>
Re: if ($x in @a) equivalent in perl? <godzilla@stomp.stomp.tokyo>
Re: if ($x in @a) equivalent in perl? <pne-news-20010512@newton.digitalspace.net>
Re: if ($x in @a) equivalent in perl? (Dave Bailey)
Re: if ($x in @a) equivalent in perl? <godzilla@stomp.stomp.tokyo>
Re: if ($x in @a) equivalent in perl? (Rudolf Polzer)
Re: if ($x in @a) equivalent in perl? (Rudolf Polzer)
Re: if ($x in @a) equivalent in perl? <thoren@southern-division.com>
Re: if ($x in @a) equivalent in perl? <bernie@fantasyfarm.com>
Re: If statement question (Rudolf Polzer)
Re: Is this possible with Perl?? <pne-news-20010512@newton.digitalspace.net>
new Regular Expression extensions? (help?) <xris@dont.send.spam>
Re: new Regular Expression extensions? (help?) <xris@dont.send.spam>
Re: new Regular Expression extensions? (help?) <keesh@users.pleaseremovethisbit.sourceforge.net>
Perl and AS400 <osipra@wanadoo.fr>
Re: Proposed new pragma: caution. <comdog@panix.com>
Re: Proposed new pragma: caution. (Anno Siegel)
regex or s/// optimization? <xris@dont.send.spam>
Re: regex or s/// optimization? <keesh@users.pleaseremovethisbit.sourceforge.net>
Re: Removing blank lines at beginng/end of a file <pne-news-20010512@newton.digitalspace.net>
Re: Removing blank lines at beginng/end of a file (Peter J. Acklam)
Re: setting environment variables <pne-news-20010512@newton.digitalspace.net>
Re: Unicode character (was: Re: If statement question) <pne-news-20010512@newton.digitalspace.net>
Re: Unicode character (was: Re: If statement question) (Rudolf Polzer)
Re: Unicode character (was: Re: If statement question) <flavell@mail.cern.ch>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 May 2001 21:42:07 GMT
From: "Dean Arnold" <darnold@earthlink.net>
Subject: ANNOUNCE: DBD::Chart 0.40 available
Message-Id: <tfpqau4vlidcf8@corp.supernews.com>
DBD::Chart 0.40 is now available from either
CPAN or at http://home.earthlink.net/~darnold/dbdchart/.
Changes from 0.30:
- add Y-MAX and Y-MIN properties for barcharts
- fixed problem with last column definitions in CREATE TABLE
- fixed problem with FORMAT property
FYI: DBD::Chart is a Perl DBI driver abstraction for rendering charts
and graphs using a variant of SQL. Review the DBD::Chart homepage at
http://home.earthlink.net/~darnold/dbdchart/ for detailed
information.
Regards,
Dean Arnold
------------------------------
Date: Sat, 12 May 2001 14:04:38 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: basic TRUE / FALSE
Message-Id: <slrn9fq9mm.fr1.eins@www42.t-offline.de>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> On Thu, 10 May 2001 20:04:31 +0200,
> Rudolf Polzer <eins@durchnull.de> wrote:
> > Todd Smith <todd@designsouth.net> wrote:
> >> >
> >> > my $showvar = TRUE;
> >> >
> >> > I can't find anything in the FAQs or docs about use of these things. Can
> >> I
> >> > not use them this way?
> >> >
> >>
> >>
> >> no, use 0 or 1
> >
> > and if he really wants to use TRUE and FALSE:
> >
> > use constant TRUE => 1;
> > use constant FALSE => 0;
>
> As long as it's only used for assignment. Perl has many different
> possible values that are true and many that are false. Comparisons
> against above constant are doomed to fail unexpectedly.
>
> my $foo = "";
>
> $foo is false from Perl's perspective, but not from the perspective of
> the constants. Besides that, $foo is meant to be a string, and the
> constant FALSE is an integer. Which comparison parameter are you going
> to use?
>
> And what about
>
> my $foo = "0 but true";
>
> suddenly, the true value of $foo compares numerically equal to FALSE. Is
> that what you want?
>
> Do NOT get into the habit of using TRUE and FALSE as if they're really
> the magical values they should be. Learn what constitutes a true and
> false value in Perl, and use that.
I do know about this. I would never write something like
if (x = false)
in C++ or
if x = false
in Pascal; I would use ! or not for this and therefore I did not think about
this. Normally TRUE and FALSE are only needed for initialization of variables
or in logical expressions.
Even in C++, a comparison with true is wrong since
2 = true
returns false.
--
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the current directory to your
(<*>){++$n;int rand$n or$s # signature file. Use at your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer
------------------------------
Date: 12 May 2001 10:12:30 +0100
From: nobull@mail.com
Subject: Re: finding all uses of a file or module at runtime
Message-Id: <u9heyr7wxt.fsf@wcl-l.bham.ac.uk>
nobull@mail.com writes:
> Anyhow here's one way you could do it. Rename MP.pm to MP.pm.orig and
> create a new file called MP.pm that looks like this:
>
> require 'MP.pm.orig';
>
> unless (@Ugly::Hack::callers) {
> # First time only
> eval 'END { print STDERR "MP was required by: @Ugly::Hack::callers\n"; }';
> }
>
> push @Ugly::Hack::callers, (caller)[1];
> delete $INC{'MP.pm'}; # Forget that I've been required already
> 1;
After posting that I realised that the delete() should be moved to
before the require() so that we don't miss any circular requirements.
Oh, and a hash would have been more appropriate that an array as
sometimes require() statements appear deep inside loops.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 12 May 2001 07:59:17 GMT
From: myriad@RemoveThis.club-internet.fr (Didier & Olivier Guillion)
Subject: Re: Forcing default filename
Message-Id: <3afcec65.3380901@news.club-internet.fr>
On Fri, 11 May 2001 21:53:47 -0400, Marshall Dudley
<mdudley@execonn.com> wrote:
> [...] Is there any way to tag the filename to the transfer so that the browser
>will default to the properl filename?
To default the filename, I use the following in my HTML page :
<FORM method=GET action="/cgi-bin/download.pl/filenametodownload.tgz">
it works on most of the browsers, I think. If you find a better way,
please tell me.
Regards,
Olivier Guillion
Myriad software
France
------------------------------
Date: 12 May 2001 11:17:34 +0100
From: andrew@white.oaktree.co.uk (Andrew Clover)
Subject: Re: Forcing default filename
Message-Id: <9dj2ju$dud$1@white.oaktree.co.uk>
Marshall Dudley <mdudley@execonn.com> wrote four times for some reason:
> The second problem is that with the file in the download path, there is
> a security issue where anyone could download the file until it is
> deleted.
Yes. Don't do that.
> Is there any way to tag the filename to the transfer so that the browser
> will default to the properl filename?
Indeed! HTTP header:
Content-Disposition: inline; filename="something.tar.whatever"
END
------------------------------
Date: Sat, 12 May 2001 16:10:52 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Forcing default filename
Message-Id: <slrn9fqh3c.1i7.eins@www42.t-offline.de>
Andrew Clover <andrew@white.oaktree.co.uk> wrote:
> Indeed! HTTP header:
>
> Content-Disposition: inline; filename="something.tar.whatever"
Which does not work with many browsers. Forget it, use the PATH_INFO trick
(add / and the filename to the URL) instead.
--
To view the lower part of this signature, apply ROT13 to the whole message.
Gb ivrj gur hccre cneg bs guvf fvtangher, nccyl EBG13 gb gur jubyr zrffntr.
------------------------------
Date: Sat, 12 May 2001 12:02:29 +0100
From: "scott.bell1" <scott.bell1@ntlworld.com>
Subject: Help
Message-Id: <lH8L6.12637$577.2239598@news2-win.server.ntlworld.com>
Can anyone tell me of a website that explains the basics of CGI?
--
Scott Bell
------------------------------
Date: Fri, 11 May 2001 22:35:34 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <3AFCCBA6.CE5E5A84@stomp.stomp.tokyo>
Dave Bailey wrote:
> Godzilla! wrote:
> > For those not paying close attention, I must amend my claim
> > of seven-hundred percent faster, previously made. I neglected
> > to remove qw quote word syntax from my test script, second
> > code snippet. I am wrong. My method is only slightly faster
> > for running through the alphabet, than is grep.
> > How this for honesty?
> It's an excellent start.
Despite my grammar?
> However, you've neglected one final
> thing, which I've saved for last.
Oh my, now aren't you just the large phallus mighty warrior!!
* shivers *
I am so intimidated.
> Take note of the subject of this thread:
> "if ($x in @a) equivalent in perl?"
> In particular, note the "$x" part. This means that the poster
> needs a method which allows the use of variables, not just
> barewords.
Gosh, you speak of and defend the original article as
if you personally authored it. Goodness, goodness!
"I think the grep() solution will work, whever I need it
(I was just curious, didn't have a real application for it at the moment)."
Shirley you didn't make that remark! I mean, just because
I am very familiar with your idioms in language usage,
writing style and your psychotically obsessive defense of grep...
nah... couldn't be....
SHEEEEE HAAAAW HAAAW HAW!
Meanwhile, back at the $x ranch....
No, you are setting your own parameters just I did.
What I did note is the originating "author" set no
parameters and, I set my own, very clearly. These
clearly set parameters of mine, you are delibrately
ignoring at the beckoning of your fragile ego,
having been bruised so very many times by me.
I can play slippery semantics, but am not psychotically
driven to do so being personally secure and confident.
$x means anything and everything. It is a symbolic
representation of the unknown. There ya go!
* laughs *
> Unfortunately for you, tr does not do this unless
> you wrap it inside an eval. Wrapping tr inside the eval, as
> you must do in order to use variables, slows it down dramatically.
Irrelevant. This is outside my set parameters. You are
grasping at straws to cover for your outlandish and
rather rude opening volley. You are a "what if wimp"
waving around a noodle sized phallus.
> There is also the matter of tr returning substring matches as
> well as equality matches, of course. That fact alone should
> have rendered the rest of this discussion moot.
"...rendered the rest of this discussion moot."
A veiled desperate plea for me to not respond!
Hmm... I thought it is i before e except after c.
Not at all. You have missed something and missed something
else even more important. In my original article I set clear
parameters, which you ignore, and I added further parameters
specifying, paraphrased, "average circumstances."
Grep, as I stated is a bad choice for what the "author" asks,
an if conditional regarding an array, despite not setting
parameters. I also stated grep becomes less efficient as
the size of an array increases. So far, I have only dealt
with small arrays, not an "average" array.
Using your what if parameters of multiple instances and
finding at least one match, grep is slower than my alternative
method using index in place of transliteration to meet your
inane "what if" multiple ego masturbation matches.
You have said "Unfortunately for you...." and in keeping
with my talent for turning tables, I will take my turn
saying, "unfortunately for you."
Your misfortune is being jerked around by your ego and
being beguiled by your own arrogance. You have not performed
your homework being so laughably arrogant. You have not
bothered to run tests on what I have stated.
With just a slight increase in array size, grep shows
significant slowing. Should I increase my test array
size to an average array size, you will have more
crow to eat than you can chew. Salt and pepper?
You are not afraid to test what I have said, are you?
Are you brave enough to be as honest as myself? Try
it. Run tests with incrementally increasing array
size and observe results. You know I have, long ago.
So, you gonna come out of hiding and face me?
Are you still upset with me for my rather charming
display of civil disobedience today? Listen, why
don't you forbid displays of civil disobedience in
your Cabal FAQ for this newsgroup, Frank?
* feeling spunky, she assumes a Josephine Baker de résistance character *
"Since I personified the savage on the stage,
I tried to be as civilized as possible in daily life."
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (100000,
{
'name1' =>
'$found ="false";
@Array = qw (godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls);
if (grep {rocks eq $_} @Array)
{ $found = "true"; }',
'name2' =>
'$found ="false";
@Array = qw (godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls
godzilla rocks and rolls godzilla rocks and rolls);
if (index ("@Array", "rocks"))
{ $found = "true"; }',
} );
}
exit;
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 100000 iterations of name1, name2...
name1: 8 wallclock secs ( 8.18 usr + 0.00 sys = 8.19 CPU) @ 12224.94/s
name2: 7 wallclock secs ( 7.19 usr + 0.00 sys = 7.19 CPU) @ 13908.21/s
Run Two:
Benchmark: timing 100000 iterations of name1, name2...
name1: 7 wallclock secs ( 8.19 usr + 0.00 sys = 8.24 CPU) @ 12210.01/s
name2: 7 wallclock secs ( 7.25 usr + 0.00 sys = 7.22 CPU) @ 13793.10/s
Run Three:
Benchmark: timing 100000 iterations of name1, name2...
name1: 9 wallclock secs ( 8.29 usr + 0.00 sys = 8.29 CPU) @ 12062.73/s
name2: 7 wallclock secs ( 7.25 usr + 0.00 sys = 7.20 CPU) @ 13793.10/s
------------------------------
Date: Sat, 12 May 2001 07:41:29 +0200
From: Philip Newton <pne-news-20010512@newton.digitalspace.net>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <8ohpfts2jvtc49t18fe4dio8hars2jm6ak@4ax.com>
On Sat, 12 May 2001 02:39:50 GMT, Ala Qumsieh <aqumsieh@hyperchip.com> wrote:
> I'd rather do it less elegantly and save on execution time:
>
> my $found = 0;
> for my $item (@array) {
> if ($item eq $x) {
> $found = 1;
> last;
> }
> }
>
> if ($found) {
> # found it.
> }
Wouldn't that possibly take longer, due to the larger number of Perl ops that
have to be executed?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 12 May 2001 06:07:44 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <slrn9fpahk.ee7.dave@sydney.daveb.net>
On Fri, 11 May 2001 22:35:34 -0700, Godzilla!
<godzilla@stomp.stomp.tokyo> wrote:
>Dave Bailey wrote:
>> Take note of the subject of this thread:
>>
>> "if ($x in @a) equivalent in perl?"
>>
>> In particular, note the "$x" part. This means that the poster
>> needs a method which allows the use of variables, not just
>> barewords.
[...]
>I can play slippery semantics...
Not slippery enough, alas.
[...]
>$x means anything and everything. It is a symbolic
>representation of the unknown.
Can it be used in tr without wrapping it in eval?
>> Unfortunately for you, tr does not do this unless
>> you wrap it inside an eval. Wrapping tr inside the eval, as
>> you must do in order to use variables, slows it down dramatically.
>
>Irrelevant. This is outside my set parameters.
Then you've answered a question which was not asked, and you've
answered it incorrectly (substring matches, remember?) to boot.
This has already been established, so if you wish to continue,
please do so by email (to my yahoo account). I am finished with
this thread.
--
Dave Bailey
davidb54@yahoo.com
------------------------------
Date: Fri, 11 May 2001 23:28:45 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <3AFCD81D.57887F1A@stomp.stomp.tokyo>
Dave Bailey wrote:
> Godzilla! wrote:
> > Dave Bailey wrote:
(snippage)
> > I can play slippery semantics...
> Not slippery enough, alas.
More slippery than snot, I'd say!
> ...so if you wish to continue, please do so by email
> (to my yahoo account).
I don't do fake email accounts. Something wrong
with your regular email account?
064.003.014.003 SMTP daveb.net
For fun trivia, you have an accessible router.
064.003.014.001 router.daveb.net
Suppose I should be gracious and mind my ethics
by not mentioning your open port numbers.
> I am finished with this thread.
I should think so after my intellectually coming
down on you so hard, you have to unzip your pants
to see where you are going!
Godzilla!
------------------------------
Date: Sat, 12 May 2001 13:51:13 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <slrn9fq8tg.fr1.eins@www42.t-offline.de>
Thoren Johne <thoren@southern-division.com> wrote:
> eins@durchnull.de (Rudolf Polzer) writes:
>
> > Why not simply
> >
> > my @array = (0, 1, 2);
> > my @other = ('a', 'b', 'c');
> >
> > my %hash = map { $array[$_], $other[$_] } 0..$#array;
>
> my %hash;
> @hash{@array} = @other;
or, what the OP wants is:
my %h;
@h{@a} = ();
and then check using
exists $h{$a}
--
To view the lower part of this signature, apply ROT13 to the whole message.
Gb ivrj gur hccre cneg bs guvf fvtangher, nccyl EBG13 gb gur jubyr zrffntr.
------------------------------
Date: Sat, 12 May 2001 13:46:51 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <slrn9fq8lb.fr1.eins@www42.t-offline.de>
Thoren Johne <thoren@southern-division.com> wrote:
> eins@durchnull.de (Rudolf Polzer) writes:
>
> > Why not simply
> >
> > my @array = (0, 1, 2);
> > my @other = ('a', 'b', 'c');
> >
> > my %hash = map { $array[$_], $other[$_] } 0..$#array;
>
> my %hash;
> @hash{@array} = @other;
Thx. I forgot I can use slices... BTW: is
@hash{keys @hash} = values @hash
safe or implementation-defined like ($a++ + $a)?
--
#!/usr/bin/perl -- Exercise: prove _or_ disprove that _all_ digits
############################ displayed are 1! s/^/4711081542426/g;
use strict;$|=@_=$0=2;for(;;){do{++$0}while('@'x$0)=~/^(..+)\1+$/;
push@_,$0;for((2-@_)..0){$_[-$_]=abs($_[-$_]-$_[1-$_])}print$_[0]}
------------------------------
Date: 12 May 2001 14:01:43 +0200
From: Thoren Johne <thoren@southern-division.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <m3eltuai8o.fsf@thoren.southern-division.com>
eins@durchnull.de (Rudolf Polzer) writes:
> Thoren Johne <thoren@southern-division.com> wrote:
> > eins@durchnull.de (Rudolf Polzer) writes:
> >
> > > Why not simply
> > >
> > > my @array = (0, 1, 2);
> > > my @other = ('a', 'b', 'c');
> > >
> > > my %hash = map { $array[$_], $other[$_] } 0..$#array;
> >
> > my %hash;
> > @hash{@array} = @other;
>
> Thx. I forgot I can use slices... BTW: is
>
> @hash{keys @hash} = values @hash
that makes no sense:
%hash1 = %hash2;
> safe or implementation-defined like ($a++ + $a)?
if i got your question:
perldoc -f keys
...
The actual random order is subject to change in future
versions of perl, but it is guaranteed to be the same
order as either the values or each function produces
(given that the hash has not been modified)
...
--
# Thoren Johne - 8#X - thoren@southern-division.com
# Southern Division Classic Bikes - www.southern-division.com
END{print@=and&X&&print'','8#X'}sub X{eval(reverse'######" Hackern\ "
esrever=,$')}BEGIN{$,=32.65.110.111.116.104.101.114.32=>@==qw/Just Perl/}
------------------------------
Date: Sat, 12 May 2001 08:54:20 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <kkaqft4ui001i8hlnjq59bq4d78amaegfi@news.supernews.net>
Ala Qumsieh <aqumsieh@hyperchip.com> wrote:
}
} > In article <tfogp2ov3fhg74@corp.supernews.com>,
} > Chris Stith <mischief@velma.motion.net> wrote:
} >
} > I think the grep() solution will work, whever I need it (I was just
} > curious, didn't have a real application for it at the moment).
}
} Note that if the element you're looking for is the first one in your
} array, and your array is a million elements long, then the grep() will
} go through ALL elements of your array.
}
} I'd rather do it less elegantly and save on execution time:
use SOAPBOX;
As a general comment, I think that this is bad advice. Very few programs
have actual performance problems and very very few programmers have a
particularly good intuition about where the performance bottlenecks
actually lie (actually, it is usually, as with your apparent inclinations,
usually an error of commission rather than omission, and so that's better
said that "Most programmers have an unbelievably BAD intuition about where
the bottlenecks in their programs actually are"). Much better, IMO, to
write the program elegantly and clearly, and then mess around with
obfuscating-it-in-the-name-of-efficiency
*ONLY* when you measure it and *know* that it needs tuning [and even then:
you only tune the specific parts that actually are the 'hot spots', rather
than just 'fixing' parts that look like they may be trouble [or more likely
for most programmers: 'fixing' the parts that are most-fun to play
with..:o)]
For example:
} my $found = 0;
} for my $item (@array) {
} if ($item eq $x) {
} $found = 1;
} last;
} }
} }
}
} if ($found) {
} # found it.
} }
This loop is actually quite a bit more work (for Perl to execute the loop)
than the simple/obvious/perlish 'grep' approach. Also, to my eye, MUCH
less clear as to what it's doing [and so a potentially trap/annoyance for
the next programmer to work on the program]. And I can ask: at what size
array does this approach actually become more efficient? How would you
know? Note that in counter to your "what if it is first" musing, one could
ask 'But if it *isn't* in the array, your loop is *much* worse than the
grep approach before it answers "not there". So that should give you a
hint that before you even *consider* doing this kind of mucking around,
you'd need:
1) to do measurements so that you could make statements about the necessary
size of the array (you've assuming that at a million elements your loop
will will be better. Do you actually have any reason to believe that
that's true? Maybe it is ten million? then again, maybe it is only a
thousand?
2) do some analysis to find out something about the likely distribution
of keys. E.g., if you're looking for something that is more likely to have
been recently added to the array, then it'll on average be farther into the
array and so much worse using your approach, with the limiting case being
that the key isn't in the array at all].
And then you need to do all of this analysis AGAIN against the clearer and
probably faster approach of using a parallel hash [again, this depends on
how you build your array and how often the values change, but if the array
is mostly 'read only', you could consider doing something like:
$array[N] = val
$arrayindexes{val} = N
then just completely ignore %arrayindexes until you get to your 'if $s is
in the array' test. Would this be better/worse than your brute-force loop?
It is very hard to tell. I think it'd be clearer, and *probably* more
efficient overall, but if the array contents are constantly changing [and
are being changed in dozens of places around the program] it might be that
the overhead of the hash will out weigh the efficiency of being able to do
'exists']. And the folks here can probably come up with six *other* ways
to make the loop more efficient in one way or another, if it actually
*proved*to*be* a bottleneck.
My point: your kind of suggested optimization isn't even
penny-wise/pound-foolish. It is, IMO, just plain foolish because it
presumes "solutions" where there's no reason [a priori] to believe that
there's a problem, and indeed the use of *that* solution, in the blind,
and *way* too early-on, *precludes* a sensible analysis of the program to
determine if that was even the *right* solution [since TMTOWTDI] [if, and
it's a BIG if, that particular part of the program actually proved to be a
choke point]. Basically, you are quick to sacrifice clarity and elegance
for *nothing*, which, IMO, is a very bad programming practice to slip into.
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Sat, 12 May 2001 13:56:22 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: If statement question
Message-Id: <slrn9fq975.fr1.eins@www42.t-offline.de>
Abigail <abigail@foad.org> wrote:
> Rudolf Polzer (eins@durchnull.de) wrote on MMDCCCX September MCMXCIII in
> <URL:news:slrn9fou5g.ra2.eins@www42.t-offline.de>:
> ##
> ## Is there a Perl way to say (C):
> ##
> ## for (;/*ever*/;) { ... }
>
> That boils down to:
>
> for (;;) { ... }
>
> which does the same in C as in Perl...
>
> ## for (;'ever';) { ... }
> ##
> ## works, but is 'ever' optimized away as a '1' constant?
>
> I don't understand your question. First of all, 'ever' isn't identical
> to 1; if you want to make it identical to a number, it should be 0.
> Furthermore, why do you think 1 is more optimized than 'ever'?
Just a style issue. In C I use for(;/*ever*;) to make it look like 'forever'.
I just wanted to make for(;;) in Perl look like 'forever'. I do know about
for(;;), I just wanted it to be like forever.
I tried (it nearly does what I want):
sub forever (&)
{
for (;;)
{
$_[0]->();
}
}
but it clobbers @_ when using
forever
{
print "1\n";
}
BTW: 'ever' is true read in boolean context, so
for (;'ever';)
works.
--
#!/usr/bin/perl -w -- sequences
$0=++$|;for(;;){print-length$0;$0=~s/(.)\1*/$1.length$&/ge;}print"\n";
------------------------------
Date: Sat, 12 May 2001 07:41:31 +0200
From: Philip Newton <pne-news-20010512@newton.digitalspace.net>
Subject: Re: Is this possible with Perl??
Message-Id: <67ipftkscra9j8js9gdqvsm8ons0d57t79@4ax.com>
On 12 May 2001 01:45:21 +0000, Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
wrote:
> Don't reinvent the wheel - use CPAN! DBD::RAM (or DBD::CVS) is what
> you want.
s/CVS/CSV/; it works on Comma-Separated Values, rather than the Concurrent(?)
Versioning System.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sat, 12 May 2001 01:52:11 -0500
From: xris <xris@dont.send.spam>
Subject: new Regular Expression extensions? (help?)
Message-Id: <xris-058F81.01521112052001@news.evergo.net>
In answer to a couple of questions I've asked recently, people have
occasionally used some regular expression extensions (you know, things
like (?=bla) and (?!bla) ) that I hadn't seen before, and aren't in my
perl5 (camel) book. I can only assume that these are perl 5.6 goodies
(since they don't work in macperl), and am wondering where/how I would
go about getting a list of these (I have no idea where to look in
perldoc - believe me, I've tried). It'd be really nice to have access
to some of the zero-width previous-character checkers, if only I knew
what they were.
And since they're not in my perl book (which as far as I know is the
latest one), is there a new perl5.6 book out there?
Once again, thanks a ton.
-Chris
------------------------------
Date: Sat, 12 May 2001 02:09:49 -0500
From: xris <xris@dont.send.spam>
Subject: Re: new Regular Expression extensions? (help?)
Message-Id: <xris-29489F.02094912052001@news.evergo.net>
Never mind, I answered my own question. Turns out that my ISP is
running per. 5.004, which is why I could find any info about these in
perldoc. It also means that knowing about those wonderful lookbehind
functions does me absolutely NO good because I can't use them.
oh well...
------------------------------
Date: Sat, 12 May 2001 09:41:07 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: new Regular Expression extensions? (help?)
Message-Id: <9disr3$frc$1@newsg1.svr.pol.co.uk>
In article <xris-058F81.01521112052001@news.evergo.net>, "xris"
<xris@dont.send.spam> wrote:
> In answer to a couple of questions I've asked recently, people have
> occasionally used some regular expression extensions (you know, things
> like (?=bla) and (?!bla) ) that I hadn't seen before, and aren't in my
> perl5 (camel) book. I can only assume that these are perl 5.6 goodies
> (since they don't work in macperl), and am wondering where/how I would
> go about getting a list of these (I have no idea where to look in
> perldoc - believe me, I've tried). It'd be really nice to have access
> to some of the zero-width previous-character checkers, if only I knew
> what they were.
They're in whatever the latest edition of /Perl in a Nutshell/ is.
Alternatively, whatever the Mac equivalent of 'man perlre' is should get
you there. It's about 20 pages down under the heading 'Extended
Patterns'.
HTH,
Ciaran
--
Ciaran McCreesh
mail: keesh@users.sourceforge.net
web: http://www.opensourcepan.com/
------------------------------
Date: Sat, 12 May 2001 13:02:40 +0200
From: "Osipra" <osipra@wanadoo.fr>
Subject: Perl and AS400
Message-Id: <9dj580$f7u$1@wanadoo.fr>
Hi I am trying to develop an application with the AS400 http server and the
perl port from the cpan.
I'm using an AS/400 under V4R4.
Every time I call a perl script the loading time of the Perl engine is 6
seconds.
Is there someone who has already developped an application with perl on
AS400 and have some solution for this issue.
The port from the cpan has been compiled with the *new activation group
option. Is it the reason ?
Is there someone who has tryed to compile the perl engine with different
option ?
Any help would be welcome.
Olivier Sipra
email@osipra.com
------------------------------
Date: Sat, 12 May 2001 05:13:44 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Proposed new pragma: caution.
Message-Id: <comdog-884FE7.05134412052001@news.panix.com>
In article <9dgj8u7s1r@news1.newsguy.com>, 194.203.215.187
[demerphq@hotmail.com] wrote:
> I have just applied for a CPAN id to release a new pragma.
> This pragma is intended for those of us that are too lazy to put
>
> use strict;
> use warnings;
why not just start from a template everytime you make a
script?
--
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: 12 May 2001 12:07:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Proposed new pragma: caution.
Message-Id: <9dj925$ll6$1@mamenchi.zrz.TU-Berlin.DE>
According to <194.203.215.187 [demerphq@hotmail.com]>:
> > > Any thoughts are welcome...
> >
> > Superfluous.
> >
> > Anno
>
> Which? Your thoughts or the pragma?
>
> Perhaps you might deign to expand on your reply?
What's to expand? A module, whose merits consist in replacing two
lines of "use" with a single one is superfluous.
Anno
------------------------------
Date: Sat, 12 May 2001 00:42:54 -0500
From: xris <xris@dont.send.spam>
Subject: regex or s/// optimization?
Message-Id: <xris-DE0539.00425412052001@news.evergo.net>
ok, basically, I'm trying to search through a string and convert commas
(possibly escaped with /, ) to something else, so that I can do a:
my @params = split(/\s*,\s*/, $params, shift);
on them. (I'm parsing comma-separated command parameters from within an
html page, if you're curious). Since I want to ignore commas that are
enclosed within quotes, I'm using: (pardon the line wrap)
$params =~ s/"(.+?(?!\\"))"/
my $x=$1;$x =~ s#\\?,#%%comma%%#g;"\"$x\""/sge;
Does anyone know of a better way to do this particular routine?
Preferably without having to make the second half of the s/// such a
relatively complex block?
Thanks,
Chris
------------------------------
Date: Sat, 12 May 2001 09:37:58 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: regex or s/// optimization?
Message-Id: <9disl6$id5$1@newsg3.svr.pol.co.uk>
In article <xris-DE0539.00425412052001@news.evergo.net>, "xris"
<xris@dont.send.spam> wrote:
> Since I want to ignore commas that are enclosed within quotes, I'm
> using: (pardon the line wrap)
>
> $params =~ s/"(.+?(?!\\"))"/
> my $x=$1;$x =~ s#\\?,#%%comma%%#g;"\"$x\""/sge;
>
> Does anyone know of a better way to do this particular routine?
> Preferably without having to make the second half of the s/// such a
> relatively complex block?
There's a whole load of information on doing this in /Mastering Regular
Experssions/ (O'Reilley). You might want to take a look at that if you
can...
The important thing to remember, though, is that longer regular
expressions aren't necessarily slower.
--
Ciaran McCreesh
mail: keesh@users.sourceforge.net
web: http://www.opensourcepan.com/
------------------------------
Date: Sat, 12 May 2001 07:41:30 +0200
From: Philip Newton <pne-news-20010512@newton.digitalspace.net>
Subject: Re: Removing blank lines at beginng/end of a file
Message-Id: <b4ipftgekrbqm77igqsspgf4qb488krgf5@4ax.com>
On Fri, 11 May 2001 22:35:57 -0000, cberry@cinenet.net (Craig Berry) wrote:
> $text =~ s/\n{2,}\Z/\n/;
Shouldn't that be a \z in there rather than \Z?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 12 May 2001 11:29:11 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: Removing blank lines at beginng/end of a file
Message-Id: <wkvgn7c5p6.fsf@math.uio.no>
"Kenneth Eide" <js@hotmail.com> writes:
> How would I remove ALL blank lines at the beginning, and at the
> end of a file? I've searched for help on this but I haven't
> found anything unfortunatly. Hope some of you guys could help
> me out.
Assuming a blank line is one with no non-whitespace characters:
perl -wne 'if(/\S/){$a=1;print@a,$_;@a=()}elsif($a){push@a,$_}' file
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Sat, 12 May 2001 07:12:25 +0200
From: Philip Newton <pne-news-20010512@newton.digitalspace.net>
Subject: Re: setting environment variables
Message-Id: <ksgpftcc46bru98jpp2v4c4cout6erf2hn@4ax.com>
On Sat, 12 May 2001 05:54:32 +0200, Fredrik De Vibe <fredridv@ifi.uio.no> wrote:
> "man perldoc" only gave me the alternatives
> h, v, t, u, m and l and "perldoc environment" didn't give me anything. Any
> idea why
You undoubtedly have an old Perl. I believe -q was not in there from the
beginning. I know it's in 5.005_03.
> and/or to what I can do?
Upgrade your Perl to 5.005_03, 5.6.0, or 5.6.1, depending on your tastes?
However, what perldoc -q does is basically search in the question headers of the
perlfaq[1-9].pod. You could do something similar with grep (or perl, if you
don't have grep):
grep environment <path-to-perl>/lib/pod/perlfaq*.pod
, and if you find a match, open the appropriate perlfaq manpage and search for
the header that was found.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sat, 12 May 2001 07:41:26 +0200
From: Philip Newton <pne-news-20010512@newton.digitalspace.net>
Subject: Re: Unicode character (was: Re: If statement question)
Message-Id: <0cipftgrjo7qc3e1a6a00ihp0v17tr8a70@4ax.com>
[What's with the "X-realname: Lou Moran" header? Are you following up to
yourself?]
On Sat, 12 May 2001 01:25:26 +0200, eins@durchnull.de (Rudolf Polzer) wrote:
> Lou Moran <lmoran@wtsg.com> wrote:
> > --
> > print "\x{263a}"
>
> What is this? Is it the Korean
> ____
> / \
> \____/
> ________
> ____
> / \
> \____/
>
> '0/0' character (spoken near 'ang', but forget about the 'a')?
No. What gives you that idea? HANGUL SYLLABLE EUNG is "\x{c751}".
> And if it is not the 0/0: does anyone know which it is?
Yes, of course. It's the Unicode character U+263A.
Here are a couple of ways of finding out what character that is:
- look in <path-to-perl>/lib/unicode/Unicode.301 (or whatever version you have
in your Perl distribution, assuming it's at least 5.6.0 -- though "\x{263a}"
wouldn't work under much earler versions anyway); search for /^263A/. [1]
- look in the printed Unicode standard, if you own it
- go to http://www.unicode.org/charts/ and download the appropriate PDF file
containing the character you're looking for (in this case, the largest filename
that is not greater than U+263A is U2600.pdf "Miscellaneous Symbols", so pick
that)
- go to http://www.unicode.org/charts/web.html and look at the appropriate page
with GIFs: in this case, U2600.html "Miscellaneous Symbols" (specifically,
http://charts.unicode.org/Web/U2600.html). This will give you a picture. If you
want the name as well, you'll have to download the PDF file.
- fetch ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt and look for
/^263A/ . This is essentially the file that Unicode.301 in the Perl unicode
directory came from.
Hope this helps.
Cheers,
Philip
[1] This method will, unfortunately, not work for Hangul syllables or CJKV
ideographs, since they're not in that table individually. Hangul syllables are
named algorithmically from their top, middle, and bottom sounds, while CJKV
ideographs' names are derived from their Unicode scalar value.[2]
[2] However, CJKV ideographs are explained in
ftp://ftp.unicode.org/Public/UNIDATA/Unihan.txt , if you care to fetch it (it's
a bit large, at 19 MB).
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sat, 12 May 2001 14:01:28 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Unicode character (was: Re: If statement question)
Message-Id: <slrn9fq9gn.fr1.eins@www42.t-offline.de>
Philip Newton <pne-news-20010512@newton.digitalspace.net> wrote:
> [What's with the "X-realname: Lou Moran" header? Are you following up to
> yourself?]
>
> On Sat, 12 May 2001 01:25:26 +0200, eins@durchnull.de (Rudolf Polzer) wrote:
>
> > Lou Moran <lmoran@wtsg.com> wrote:
> > > --
> > > print "\x{263a}"
> >
> > What is this? Is it the Korean
> > ____
> > / \
> > \____/
> > ________
> > ____
> > / \
> > \____/
> >
> > '0/0' character (spoken near 'ang', but forget about the 'a')?
>
> No. What gives you that idea? HANGUL SYLLABLE EUNG is "\x{c751}".
I thought it was the most interesting unicode character... I did not know
Unicode emulates Wingdings.
> > And if it is not the 0/0: does anyone know which it is?
>
> Yes, of course. It's the Unicode character U+263A.
>
> Here are a couple of ways of finding out what character that is:
>
> - look in <path-to-perl>/lib/unicode/Unicode.301 (or whatever version you have
> in your Perl distribution, assuming it's at least 5.6.0 -- though "\x{263a}"
> wouldn't work under much earler versions anyway); search for /^263A/. [1]
Thx. I found out that I can view Unicode characters using another way:
this HTML file
<FONT FACE="unifont" SIZE=7>〹</FONT>
prints the uncode character 12345 when viewed in Konqueror _and_ UTF-8 is
enabled.
--
The easiest way to kill a Linux system:
www42:~ # rm /dev/null
Also possible:
www42:~ # chmod 000 /dev/null
------------------------------
Date: Sat, 12 May 2001 13:54:57 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Unicode character (was: Re: If statement question)
Message-Id: <Pine.LNX.4.30.0105121345060.9343-100000@lxplus003.cern.ch>
On Sat, 12 May 2001, Rudolf Polzer wrote:
> <FONT FACE="unifont" SIZE=7>〹</FONT>
^^^^^^^
Maybe, but please don't do that in public! My browser would happily
display 〹 if allowed to do it; but if you try to force that
font which I haven't got, you will likely harm the result.
> prints the uncode character 12345 when viewed in Konqueror _and_ UTF-8 is
> enabled.
This would seem to imply that the browser has a similar conceptual
blunder in its design as has NN4? A properly designed HTML4 browser
understands &#bignumber; notation even if the document's character
_coding_ is, say, us-ascii, See RFC2070 for details.
On my page http://ppewww.ph.gla.ac.uk/~flavell/unicode/ there is a
link to Alan Wood's excellent Unicode resource pages, as well as a
link to my own rough-and-ready programmatically-generated test
repertoire.
f'ups set
--
Caution: product may contain traces of nut.
------------------------------
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 882
**************************************