[18722] in Perl-Users-Digest
Perl-Users Digest, Issue: 890 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 13 18:05:33 2001
Date: Sun, 13 May 2001 15:05:08 -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: <989791508-v10-i890@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 13 May 2001 Volume: 10 Number: 890
Today's topics:
Re: AND-connected search (Abigail)
Re: criteria for bulit-in functions (Abigail)
Re: Existing Script To Add Time <dodger@necrosoft.net>
Re: Existing Script To Add Time <uri@sysarch.com>
Re: Existing Script To Add Time (Anno Siegel)
HELP: loading a hash of anon subs from file... (Bruno Boettcher)
Re: if ($x in @a) equivalent in perl? <aqumsieh@hyperchip.com>
Re: if ($x in @a) equivalent in perl? <joe+usenet@sunstarsys.com>
Re: Numbers (Abigail)
Re: Numbers <bop@mypad.com>
Re: Numbers (Logan Shaw)
perl -c to file <4ss42@qsilver.queensu.ca>
Re: perl -c to file (reader of news)
Re: perl -c to file nobull@mail.com
Re: regex for html links (Dave Bailey)
Req. for help: need biometric guniea pigs <mgs21@columbia.edu>
Re: Taint <flavell@mail.cern.ch>
Re: Taint <dodger@necrosoft.net>
Re: Taint <dodger@necrosoft.net>
Re: Taint <uri@sysarch.com>
Re: Taint <comdog@panix.com>
Re: Taint <flavell@mail.cern.ch>
Re: Taint (Anno Siegel)
Re: Taint (Garry Williams)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 May 2001 20:10:37 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: AND-connected search
Message-Id: <slrn9ftqht.6tm.abigail@tsathoggua.rlyeh.net>
Logan Shaw (logan@cs.utexas.edu) wrote on MMDCCCXI September MCMXCIII in
<URL:news:9dk7hp$aqu$1@ahab.cs.utexas.edu>:
~~ In article <9dk5em$gs5$1@nets3.rz.RWTH-Aachen.DE>,
~~ Tim Lauterborn <Tim.Lauterborn@gmx.de> wrote:
~~ >I am looking for a regular expression which allows a sort of
~~ >AND-connected-search like in the following code example which unfortunately
~~ >does not work.
~~ >
~~ >$line="acd";
~~ >print ($line=~/a&&c/);
~~ >
~~ >The expression should be true if $line contains a AND c and wrong if $line
~~ >contains for example only a.
~~
~~ /a.*c|c.*a/
~~
~~ Unfortunately, this does not work too well if you want to match more
~~ more than two strings. To match a and b and c, you have to do this:
~~
~~ /a.*(b.*c|c.*b)|b.*(a.*c|c.*a)|c.*(a.*b|b.*a)/
~~
~~ As you can tell, the size of this regular expression will grow
~~ exponentially.
~~
~~ So, instead, it's usually best to do something like this:
~~
~~ /a/ and /b/ and /c/
~~
~~ That grows linearly, which makes for much shorter code and faster
~~ execution too.
But doesn't work well if you need to supply the regex externally, from
for instance a command line, or a configuration file.
This, however, does, and grows lineary:
/^(?=.*a)(?=.*b)(?=.*c)/s
Life becomes more complicating if the subexpressions can overlap, but
you require non overlapping matches.
Abigail
--
split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Sun, 13 May 2001 19:37:28 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: criteria for bulit-in functions
Message-Id: <slrn9ftojo.6tm.abigail@tsathoggua.rlyeh.net>
Wei-hao Lin (whlin@Venus.bblab.cgmh.com.tw) wrote on MMDCCCXI September
MCMXCIII in <URL:news:slrn9fqigq.v2f.whlin@Venus.bblab.cgmh.com.tw>:
!!
!! While writing codes of copying files in PERL, a question strikes me.
!! Why are some *nix commands (chown(1), chmod(1), just name a few) built-in
!! while others (cp(1), mv(1), etc) are not? What are the criteria?
It isn't that commands are build in - it's the C API that's showing.
It's not chown(1) or chmod(1) that are build in, but chown(2) and
chmod(2). That's why chmod() for instance doesn't have symbolic mode -
just numerical, because that's how it's done in the C API.
Some C API have a command equivalence, sometimes with the same name
(like chmod and chown). Others have a different name - mv is the command
equivalence of the C API 'rename', which is 'rename' in Perl...
There's no C API for copying a file, so no copy primitive in Perl...
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Sun, 13 May 2001 19:03:35 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Existing Script To Add Time
Message-Id: <bUAL6.222$F46.42202@news1.rdc2.pa.home.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9dmhtj$dp6$1@mamenchi.zrz.TU-Berlin.DE...
> According to Dodger <dodger@necrosoft.net>:
> my ($starth, $startm, $stoph, $stopm) = map split( /:/), @ARGV;
> my $minutes = 60 * ($stoph - $starth) + $stopm - $startm;
> $minutes += 24 * 60 if $minutes < 0; # not specified, but plausible
> printf "%02d:%02d\n", int $minutes / 60, $minutes % 60;
Yes, of course, but I wouldn't expect an acolyte to be able to follow it.
> Except perhaps for the map() everything is absolutely straightforward
> and, with a moment's thought, should have occurred to you as well. A
> little diligence is required.
See above. Actually something very similar had, but I felt that something
with a more obvious flow would be more helpful to someone asking this.
> > No offense, but I will continue to post as I do, with on-the-fly code,
for
> > simple tasks such as this. If I have reason to doubt either a logic flow
or
> > a bit o' Perl that's particularly weird, I will log in and test it. If
it's
>
> [snip]
>
> You will be criticized.
I never expected not to be. However, such should be correct criticisms, not
simply postings of more compact ways to say things that will undoubtedly
confuse those new to Perl.
I did, however. expect to not be flamed. I continue to expect such, as you
will desist in such activity, now.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Sun, 13 May 2001 19:19:27 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Existing Script To Add Time
Message-Id: <x7lmo19hum.fsf@home.sysarch.com>
>>>>> "D" == Dodger <dodger@necrosoft.net> writes:
>> my ($starth, $startm, $stoph, $stopm) = map split( /:/), @ARGV;
>> my $minutes = 60 * ($stoph - $starth) + $stopm - $startm;
>> $minutes += 24 * 60 if $minutes < 0; # not specified, but plausible
>> printf "%02d:%02d\n", int $minutes / 60, $minutes % 60;
D> Yes, of course, but I wouldn't expect an acolyte to be able to
D> follow it.
you don't write programs for acolytes. you teach them to write better
programs.
D> See above. Actually something very similar had, but I felt that something
D> with a more obvious flow would be more helpful to someone asking this.
and is it more obvious to teach bad coding style?
D> I never expected not to be. However, such should be correct
D> criticisms, not simply postings of more compact ways to say things
D> that will undoubtedly confuse those new to Perl.
this is not a newbie group. many people of all skill levels read this
and most want to see better ways of coding. posting so only newbies can
understand is worthless. if they don't understand something they can ask
about it.
those 4 lines are not so complex. they can be made slightly easier to
understand by making the map line into 2 calls of split in two separate
statements. that use of map to set 4 different vars is not a good use of
it IMO.
D> I did, however. expect to not be flamed. I continue to expect such,
D> as you will desist in such activity, now.
hahah! ow, you post here, you get criticized here. you have no control
over the style of them and you can only control your reaction to
them. hmmm, which choice should you make? counterflame everyone who
criticises you (oh, we have a resident moron who does that already)? or
learn to thicken your usenet hide?
which one to do?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 13 May 2001 20:16:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Existing Script To Add Time
Message-Id: <9dmq2p$iqo$1@mamenchi.zrz.TU-Berlin.DE>
According to Dodger <dodger@necrosoft.net>:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9dmhtj$dp6$1@mamenchi.zrz.TU-Berlin.DE...
> > According to Dodger <dodger@necrosoft.net>:
> > my ($starth, $startm, $stoph, $stopm) = map split( /:/), @ARGV;
> > my $minutes = 60 * ($stoph - $starth) + $stopm - $startm;
> > $minutes += 24 * 60 if $minutes < 0; # not specified, but plausible
> > printf "%02d:%02d\n", int $minutes / 60, $minutes % 60;
>
> Yes, of course, but I wouldn't expect an acolyte to be able to follow it.
What's hard about it? Except for the map() thing, which would indeed
better be written in two lines of split() (acknowledged, Uri), if I had
to present the code to someone unfamiliar with programming concepts, it
might look like this:
# Calculate time difference in minutes:
my $minutes = 60 * ($stoph - $starth) + $stopm - $startm;
# If difference is negative, assume stop time 24 hours later:
$minutes += 24 * 60 if $minutes < 0;
# Print full hours and remaining minutes:
printf "%02d:%02d\n", int $minutes / 60, $minutes % 60;
Someone unable to follow that with the help of perldoc should
probably not be programming. Do you really propose, calculating
full hours and minutes in a while-loop is clearer?
[snip]
> > You will be criticized.
>
> I never expected not to be. However, such should be correct criticisms, not
> simply postings of more compact ways to say things that will undoubtedly
> confuse those new to Perl.
I submit that your code was *more* confusing and certainly showed bad
coding practices. We want some quality here.
> I did, however. expect to not be flamed. I continue to expect such, as you
> will desist in such activity, now.
Yikes, what letter-writer's handbook did that come from?
Anno
------------------------------
Date: 13 May 2001 23:19:44 GMT
From: bboett@erm6.u-strasbg.fr (Bruno Boettcher)
Subject: HELP: loading a hash of anon subs from file...
Message-Id: <9dn4qg$7r4$1@news.u-strasbg.fr>
hello!
i am in the progress of writing an irc bot in perl, since it has to
answer to a lot of triggers, i put the triggers into a hash with
references to anon subroutines, like this:
'PART' => sub
{
my $sLine = shift;
$sLine =~ s/:(.*)$/$1/;
... and some more code ....
},
'JOIN' => sub
{
... even more code ...
}
and then in the event loop i make :
if ($reactions->{$commandtag})
{
&{$reactions->{$commandtag}}( $sLine, $sGtmp );
}
now this works fine, but now i thought, that it would be nice to have
those triggers outside of the main file. That way i would be able to
modify the behaviour of the bot without needing to restart it, only
issue a reload command ...
so i put all the lines of the hash into a ':' separated file. Loaded
that file into the hash, but when i try to use the subs, i get the
following error: Can't use string ("sub { SendServer( 'PRIVMSG '.$se")
as a subroutine ref while "strict refs" in use at ./zebot.pl line 398,
<GEN1> line 34.
Now i suppose that the error message is truncated and that the line was
complete, at least in the hash its complete.....
So i am surely missing something obvious here, but i don't get it....
i tryed to eval the incoming subs, but this was even worse, eval doesn'T
seem to return a reference of any sort....
so i would really need some help here...
--
bboett at erm1 dot u-strasbg dot fr
http://erm6.u-strasbg.fr/~bboett
==============================================================
Unsolicited commercial email is NOT welcome at this email address
------------------------------
Date: Sun, 13 May 2001 21:17:02 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <m3bsox6ja1.fsf@alquds.qumsieh.homeip.net>
> 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)]
I totally agree. Personally, I don't bother much with spending time
optimizing code before I finish writing working code. Actually, I've had
cases where my scripts would take days to run, and then I'd optimize it
to work in 15 mins (ok .. those were extreme cases where I was doing
something stupid, but it shows the spirit!)
> 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.
I'm not sure about this statement. I recall reading somewhere (probably
on p5p) that foreach loops were pretty well optimized. I'm interested in
a benchmark if you have one.
> 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].
This code is not that obscure. I think it is easier to read (for
non-Perlers) than:
my $found = grep {$x eq $_} @array;
> And I can ask: at what size
> array does this approach actually become more efficient? How would you
> know?
I'd have to say that this seems to me to be application
dependent. Differents apps will have different data. I was merely giving
an example in my reply, but I don't have definite numbers.
> 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".
Again, I'm interested in benchmarks. My experience with the Benchmark
module has been less than satisfactory :)
> 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?
Right. I have no reasons. It was just a figurative example, as I said
before.
> 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].
As I also said, this is application dependent. I agree with you.
> 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.
I would disagree slightly there. I would construct the hash right before
I need it and then undef() it right after to let Perl recycle the
memory. Again, it's application dependent and if I need the hash more
than once, I'd probably use your approach and just construct the hash
once (probably as I'm filling the array) and get it over with.
> Basically, you are quick to sacrifice clarity and elegance
> for *nothing*, which, IMO, is a very bad programming practice to slip into.
Hey, it was only a suggestion :)
Coming to think about it, if you really want to optimize for memory and
speed, then you shouldn't be using Perl. Hashes are one of Perl's
strongest features. It's ideal for this kind of application. For small
arrays, grep() is the best thing to go with.
--Ala
------------------------------
Date: 13 May 2001 18:00:57 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: if ($x in @a) equivalent in perl?
Message-Id: <m3ofsw3o4m.fsf@mumonkan.sunstarsys.com>
Ala Qumsieh <aqumsieh@hyperchip.com> writes:
> > This loop is actually quite a bit more work (for Perl to execute the loop)
> > than the simple/obvious/perlish 'grep' approach.
>
> I'm not sure about this statement. I recall reading somewhere (probably
> on p5p) that foreach loops were pretty well optimized. I'm interested in
> a benchmark if you have one.
% cat try.pl
#!/usr/bin/perl
use Benchmark;
@a = "a" .. "z";
timethese -5, {
for => q/ $m = 0; for (@a){ $_ eq $ARGV[0] and $m=1 and last }/,
grep => q/ $m = grep {$_ eq $ARGV[0]} @a/,
hash => q/ my %h; undef @h{@a}; $m = exists $h{$ARGV[0]}/,
};
% ./try.pl a
for: 46097.80/s (n=230950)
grep: 1855.29/s (n=9295)
hash: 7554.69/s (n=37849)
% ./try.pl i
for: 7419.16/s (n=37170)
grep: 1833.67/s (n=9205)
hash: 7509.70/s (n=37924)
% ./try.pl z
for: 2652.80/s (n=13264)
grep: 1836.33/s (n=9200)
hash: 7531.60/s (n=37658)
--
Quintessential Williams: reintermediate efficient initiatives
------------------------------
Date: Sun, 13 May 2001 20:47:57 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Numbers
Message-Id: <slrn9ftsnt.6tm.abigail@tsathoggua.rlyeh.net>
Ciaran McCreesh (keesh@users.pleaseremovethisbit.sourceforge.net) wrote
on MMDCCCXII September MCMXCIII in <URL:news:9dmdt6$34i$1@news8.svr.pol.co.uk>:
}} In article <tHyL6.80061$_f3.1473777@news20.bellglobal.com>, "flash"
}} <bop@mypad.com> wrote:
}}
}} > Hello I need 6 numbers that when you add any individual combination you
}} > always get a unique number
}} >
}} > (like chmod numbers) (1,2,4)
}} >
}} > If anyone knows of anymore, i could really use them, or if someone knows
}} > of a mathematical way to find them.
}}
}} 1, 2, 4, 8, 16, 32
}}
}} Just start with 1 and double each time to get the next one.
The sequence:
(10 ** n), non-negative integer n
will do, in any base.
Abigail
--
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${${@}}[$#{@{${@}}}]'
------------------------------
Date: Sun, 13 May 2001 21:12:04 GMT
From: "flash" <bop@mypad.com>
Subject: Re: Numbers
Message-Id: <EMCL6.30343$yw.786529@news20.bellglobal.com>
I was thinkin
1
10
100
1000
but i found 1
2
4
8
16
(2^x)
to work better for what i need.
"Abigail" <abigail@foad.org> wrote in message
news:slrn9ftsnt.6tm.abigail@tsathoggua.rlyeh.net...
> Ciaran McCreesh (keesh@users.pleaseremovethisbit.sourceforge.net) wrote
> on MMDCCCXII September MCMXCIII in
<URL:news:9dmdt6$34i$1@news8.svr.pol.co.uk>:
> }} In article <tHyL6.80061$_f3.1473777@news20.bellglobal.com>, "flash"
> }} <bop@mypad.com> wrote:
> }}
> }} > Hello I need 6 numbers that when you add any individual combination
you
> }} > always get a unique number
> }} >
> }} > (like chmod numbers) (1,2,4)
> }} >
> }} > If anyone knows of anymore, i could really use them, or if someone
knows
> }} > of a mathematical way to find them.
> }}
> }} 1, 2, 4, 8, 16, 32
> }}
> }} Just start with 1 and double each time to get the next one.
>
>
> The sequence:
>
> (10 ** n), non-negative integer n
>
> will do, in any base.
>
>
> Abigail
> --
> perl -we 'eval {die ["Just another Perl Hacker\n"]}; print
${${@}}[$#{@{${@}}}]'
------------------------------
Date: 13 May 2001 16:25:29 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Numbers
Message-Id: <9dmu49$hv7$1@ahab.cs.utexas.edu>
In article <EMCL6.30343$yw.786529@news20.bellglobal.com>,
flash <bop@mypad.com> wrote:
>I was thinkin
>1
>10
>100
>1000
>
>but i found 1
>2
>4
>8
>16
>
>(2^x)
>to work better for what i need.
Read Abigail's post again. She said in any base.
If you are thinking in binary, then this:
10
100
1000
10000
is equivalent to this (in decimal):
2
4
8
16
So, Abigail's answer includes that in it.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Sun, 13 May 2001 15:01:10 -0400
From: "Stéfan Sinclair" <4ss42@qsilver.queensu.ca>
Subject: perl -c to file
Message-Id: <9dmlq6$hgi$1@knot.queensu.ca>
Dear all,
Could someone please tell me how I can dump the results of a perl -c
[filename] to a file in Unix?
I've tried all sorts of combinations including the obvious:
perl -c scriptname > results
I think the problem is that the compiler somehow doesn't print its results
to the standard output the way I'm used to, so my results file always ends
up empty. I've noticed something of the same nature when I try a more/less
with the piped results of a perl -c (since the screens can sometimes be very
long) - but again, the standard out doesn't appear to function as I would
expect.
This is for a simple web-based script editor, so I don't think debugger
approaches would be much use. I'm trying to determine whether or not a
script will succeed before redirecting to it (so I can't just eval the
script, and I want to run it alone, not as a module).
As an intermediate perl/unix person, there may be something obvious that I'm
missing.
Thanks,
Stéfan
--------------------------------------------------
Stéfan Sinclair, PhD - Queen's University (Canada)
------------------------------
Date: Sun, 13 May 2001 19:50:03 GMT
From: newsreader@mediaone.net (reader of news)
Subject: Re: perl -c to file
Message-Id: <slrn9ftpcf.731.newsreader@dragon.universe>
On Sun, 13 May 2001 15:01:10 -0400,
Stéfan Sinclair <4ss42@qsilver.queensu.ca> wrote:
>Dear all,
>
>Could someone please tell me how I can dump the results of a perl -c
>[filename] to a file in Unix?
>
>I've tried all sorts of combinations including the obvious:
>
>perl -c scriptname > results
>
>
Try
$ perl -c potential.bad.script > log.file 2>&1
------------------------------
Date: 13 May 2001 20:43:31 +0100
From: nobull@mail.com
Subject: Re: perl -c to file
Message-Id: <u9itj5kpb0.fsf@wcl-l.bham.ac.uk>
"Stéfan Sinclair" <4ss42@qsilver.queensu.ca> writes:
> ... in Unix?
> perl -c scriptname > results
> I think the problem is that the compiler somehow doesn't print its results
> to the standard output..
> As an intermediate perl/unix person, there may be something obvious that I'm
> missing.
What you are missing is the fact that the output of perl -c goes to
STDERR not STDOUT.
To redidect STDOUT in Unix
perl -c scriptname 2> results
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 13 May 2001 19:13:57 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: regex for html links
Message-Id: <slrn9ftcvq.2nc.dave@sydney.daveb.net>
On Sat, 12 May 2001 19:14:44 -0700, Godzilla!
<godzilla@stomp.stomp.tokyo> wrote:
>Moriarty wrote:
>
>> I'm trying to make a regex to find web links in a text file
>> and ad <a href stuff around it to link it up.
[...]
>There are alternative methods to use of a
>regex which may or may not be more efficient.
>I use an index and substr method for this,
>which will be very efficient, inherently.
>Chances are, more efficient than a regex
>but I would need to benchmark to be sure.
I wouldn't. Your code is phenomenally inefficient. You manage to take
an O(n) problem and provide an O(n^2) solution, then surmise (incorrectly,
of course) that your solution may be more efficient than a regex search
and replace. You don't understand the sentence I just wrote, but if you
did, you would see that you must live in an inverted world. Perhaps that
is why you always talk out of your ass, as you will no doubt do in the
lengthy, discombobulated, irrelevant, wrong and thoroughly uninteresting
reply you are about to compose.
>Although my code looks complex, written
>in Plain English, it is easy to understand
>and is quite logical in approach.
A one line regular expression does the job better, and is also quite
comprehensible to those of us who understand Perl.
--
Dave Bailey
davidb54@yahoo.com
------------------------------
Date: Sun, 13 May 2001 17:03:44 -0400
From: Mike Schiraldi <mgs21@columbia.edu>
Subject: Req. for help: need biometric guniea pigs
Message-Id: <Pine.GSO.4.10.10105131644070.2204-100000@aloha.cc.columbia.edu>
I'm playing around with some simple biometrics - measuring the time
between keystrokes for a standard phrase, like "The quick brown fox" or
"My voice is my passport" ... i'm using a very simple routine to compare
results (basically an n-dimensional version of the distance formula), but
i think i might be able to get good results despite such a simple
approach.
That's where you people come in. I was hoping a few or a lot of you would
be willing to take the time to run the following script and send me the
output. It will ask you to type a short phrase. Then, if you run it with
an $ARGV[0] of your name, it will add your timings to the (initially
non-existent) datafile. If you called it with no options, it will try to
match you to an entry in the datafile.
Obviously it works best if you're sitting at the box it's running on --
i.e. no network latency. If you can't do that, i'd still like to see your
results, but let me know the details. And sorry, no Dvorak typists just
yet.
Finally, here are the CPAN urls for the two required modules, to save you
the trouble if you don't already have them:
http://www.cpan.org/authors/id/K/KJ/KJALB/TermReadKey-2.14.tar.gz
http://www.cpan.org/authors/id/D/DE/DEWEG/Time-HiRes-01.20.tar.gz
Thanks again for anyone willing to help.
#! /usr/bin/perl -w
use Time::HiRes qw(tv_interval gettimeofday);
use Term::ReadKey;
use strict;
my $PHRASE = "The quick brown fox";
my $TOLERANCE = 0.01;
# Measure the user's typing patterns
sub time_user () {
my @chars = split //, $PHRASE;
my @timings;
my $prev_time = undef;
printf "Type '$PHRASE' as fast as you can "
. "(but without making any typos)\n";
local($|) = 1;
ReadMode 5;
while (@chars) {
my $key = ReadKey -1;
next unless $key;
my $time = [gettimeofday];
my $expected = shift @chars;
if ($expected ne $key) {
ReadMode 0;
print "\nYou were supposed to type '$expected' "
. "but instead you typed '$key'\n";
exit 1;
}
print $key;
if ($prev_time) {
push @timings, tv_interval($prev_time, $time);
}
$prev_time = $time;
}
ReadMode 0;
print "\nYour timings: @timings\n";
return \@timings;
}
# Read in the timings database
sub load_timings () {
open F, "timings" or return {};
my %table;
while (<F>) {
my ($name, @timings) = split;
$table{$name} = \@timings;
}
return \%table;
}
# Write out a new timings database
sub save_timings ($) {
my $table = shift;
open F, ">timings" or die "could not open timings for writing: $!\n";
for my $name (keys %{$table}) {
print F "$name @{$table->{$name}}\n";
}
}
# Compare $a (the current user's timings) with each $b (each user in the
# database)
sub identify ($$) {
my $table = shift;
my $a = shift;
my $best;
my $winner;
for my $name (keys %{$table}) {
my $b = $table->{$name};
my $diff = 0;
for (my $i = 0; $a->[$i]; $i++) {
$diff += ($a->[$i] - $b->[$i]) ** 2;
}
print "Your timing was different from $name "
. "by a factor of $diff\n";
if (!defined $best or $diff < $best) {
$best = $diff;
$winner = $name;
}
}
return ($winner, $best);
}
my $timings = time_user;
my $table = load_timings;
if ($ARGV[0]) {
$table->{$ARGV[0]} = $timings;
save_timings ($table);
}
else {
my ($name, $diff) = identify ($table, $timings);
$name or die "Nobody's in the database yet\n";
if ($diff < $TOLERANCE) {
print "It's safe to say that you're $name\n";
}
else {
print "You didn't match anyone in the database. "
. "However, you're closest to $name\n";
}
}
------------------------------
Date: Sun, 13 May 2001 19:46:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Taint
Message-Id: <Pine.LNX.4.30.0105131946060.26045-100000@lxplus003.cern.ch>
On Sun, 13 May 2001, Dodger wrote:
> $ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
You have an extremely sick sense of humo(u)r,
------------------------------
Date: Sun, 13 May 2001 18:41:52 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Taint
Message-Id: <QzAL6.135$F46.31439@news1.rdc2.pa.home.com>
"M.J.T. Guy" <mjtg@cus.cam.ac.uk> wrote in message
news:9dmfs4$al3$1@pegasus.csx.cam.ac.uk...
> Dodger <dodger@necrosoft.net> wrote:
> >
> >everyone has referred you to perldoc perlsec. I do, too, but here's a bit
> >more:
> >
> >$ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
>
> There's a good reason why people refer to perlsec - the exaples there
> work. Your example of course does not.
>
> Please do not post untested, incorrect code. It wastes everyones
> time.
Yes, it does. It's not necessarily secure, but it won't raise taint errors.
Do not ever flame me again.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Sun, 13 May 2001 18:50:18 GMT
From: "Dodger" <dodger@necrosoft.net>
Subject: Re: Taint
Message-Id: <KHAL6.172$F46.35734@news1.rdc2.pa.home.com>
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.30.0105131946060.26045-100000@lxplus003.cern.ch...
> On Sun, 13 May 2001, Dodger wrote:
>
> > $ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
>
> You have an extremely sick sense of humo(u)r,
I wasn't making a joke.
It's not uncommon to have taint mode enacted in situations where it's
unwelcome, such as, for instance a setuid CGI that runs setuid root to
validate a login/password, but then switches to the logged-in user and does
something as that user. As a setuid script, Taint-mode will force itself
into the picture, even if you are perfectly content to let the user do
whatever silly thing they want within their own permissions, and nothing
taint-able happens before you switch UIDs.
In such cases, rationally, there should be a way to turn taint-mode off at a
certain point (for instance, after setuid to the user's uid). However, perl
doesn't allow this. The example posted quite simply removes the tainted-ness
of the variable, allowing it to be used as the author sees fit, as if taint
mode wasn't an issue.
Taint mode goes to great extremes to make sure you don't shoot your foot by
taking away all your bullets. Sometimes this is not what's needed. My
example allows you to bypass taintedness on a variable of whatever type.
If, however, the original poster's desire is to do something stupid with
de-tainted data, I provided adequate warning to them to be sure they knew
what they were doing with whatever they untainted.
--
Dodger
www.dodger.org
www.necrosoft.net
www.gothic-classifieds.com
------------------------------
Date: Sun, 13 May 2001 19:12:35 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Taint
Message-Id: <x7pudd9i61.fsf@home.sysarch.com>
>>>>> "D" == Dodger <dodger@necrosoft.net> writes:
D> "M.J.T. Guy" <mjtg@cus.cam.ac.uk> wrote in message
D> news:9dmfs4$al3$1@pegasus.csx.cam.ac.uk...
>> Dodger <dodger@necrosoft.net> wrote:
>> >
>> >everyone has referred you to perldoc perlsec. I do, too, but here's a bit
>> >more:
>> >
>> >$ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
>>
>> There's a good reason why people refer to perlsec - the exaples there
>> work. Your example of course does not.
>>
>> Please do not post untested, incorrect code. It wastes everyones
>> time.
D> Yes, it does. It's not necessarily secure, but it won't raise taint
D> errors.
then what is the point of enabling taint to begin with? you logic is
backwards. if you don't care about security, then don't taint. if you
taint, you just don't do unsecure untaint hacks.
D> Do not ever flame me again.
<the sound of dodger hitting killfiles all over the world>
if you think that is a flame (mine or mjt's), you don't know from usenet.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sun, 13 May 2001 15:33:33 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Taint
Message-Id: <comdog-43D99A.15333313052001@news.panix.com>
In article <QzAL6.135$F46.31439@news1.rdc2.pa.home.com>, "Dodger"
<dodger@necrosoft.net> wrote:
> "M.J.T. Guy" <mjtg@cus.cam.ac.uk> wrote in message
> news:9dmfs4$al3$1@pegasus.csx.cam.ac.uk...
> > Dodger <dodger@necrosoft.net> wrote:
> > >everyone has referred you to perldoc perlsec. I do, too, but here's a bit
> > >more:
> > >$ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
> > Please do not post untested, incorrect code. It wastes everyones
> > time.
> Yes, it does. It's not necessarily secure, but it won't raise taint errors.
oh really?
brian[1]$ cat taint
#!/usr/bin/perl -Tw
$ENV{PATH} =~ s/^(.*)$/$1/;
system 'echo $PATH';
__END__
brian[2]$ ./taint
Insecure $ENV{PATH} while running with -T switch at ./taint line 5.
> Do not ever flame me again.
considered yourself flamed again. if you post untested code and
insist on being at odds with documented behaviour, you will get
flamed.
--
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: Sun, 13 May 2001 21:29:19 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Taint
Message-Id: <Pine.LNX.4.30.0105132126230.26045-100000@lxplus003.cern.ch>
On Sun, 13 May 2001, Dodger addressed "M.J.T. Guy" <mjtg@cus.cam.ac.uk>
> Do not ever flame me again.
I don't know about MJTG, but I know a simple solution for that. Bye.
------------------------------
Date: 13 May 2001 20:27:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Taint
Message-Id: <9dmqn5$iqo$2@mamenchi.zrz.TU-Berlin.DE>
According to Dodger <dodger@necrosoft.net>:
> Do not ever flame me again.
Why not?
Anno
------------------------------
Date: Sun, 13 May 2001 20:35:05 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Taint
Message-Id: <slrn9ftrvp.us.garry@zfw.zvolve.net>
On Sun, 13 May 2001 18:50:18 GMT, Dodger <dodger@necrosoft.net> wrote:
> "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> news:Pine.LNX.4.30.0105131946060.26045-100000@lxplus003.cern.ch...
>> On Sun, 13 May 2001, Dodger wrote:
>>
>> > $ENV{some_env_var} =~ s/^(.*)$/$1/; # now it's clean.
>>
>> You have an extremely sick sense of humo(u)r,
>
> I wasn't making a joke.
>
> It's not uncommon to have taint mode enacted in situations where it's
> unwelcome, such as, for instance a setuid CGI that runs setuid root to
> validate a login/password, but then switches to the logged-in user and does
> something as that user. As a setuid script, Taint-mode will force itself
> into the picture, even if you are perfectly content to let the user do
> whatever silly thing they want within their own permissions, and nothing
> taint-able happens before you switch UIDs.
Then exec() the user's program after switching. No more taint
checking.
--
Garry Williams
------------------------------
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 890
**************************************