[17988] in Perl-Users-Digest
Perl-Users Digest, Issue: 148 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 06:05:31 2001
Date: Fri, 26 Jan 2001 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980507108-v10-i148@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 26 Jan 2001 Volume: 10 Number: 148
Today's topics:
Re: ActivePerl Modules Installation Problems <simon.andrews@bbsrc.ac.uk>
Best way to learn Perl? jqcordova@my-deja.com
Built-in Function Questions <brentdax1_@_earthlink.net>
Re: Built-in Function Questions (Rafael Garcia-Suarez)
Re: Built-in Function Questions <brentdax1_@_earthlink.net>
Re: Built-in Function Questions <brentdax1_@_earthlink.net>
Re: Comparing multiple values (Abigail)
Re: Dealing with x1b character <Jerome.Abela@free.fr>
Re: Error Message <brentdax1_@_earthlink.net>
Re: FAQ 1.7: Is Perl difficult to learn? <callgirl@la.znet.com>
Re: Hash of hash of arrays problem (Lou Hevly)
Re: How do you backspace(back delete) on console? nobull@mail.com
Re: How to do this regular expression? (Bernard El-Hagin)
Re: Iterating through matches to a regexp ? <Jerome.Abela@free.fr>
Re: Know Perl? Help a poor hack out with if-else state <Michael.Schlueter@philips.com>
Re: LWP/ Web Login Advice Needed (Rafael Garcia-Suarez)
Re: Precision? (was: Perl is bad at (very) simple math! (Mark Jason Dominus)
Re: Problem with Tie::StdHash / FETCH ?? <Jerome.Abela@free.fr>
regexpr as condition <qvyht@iobox.fi>
Re: Script to "rotate" the chars in a string. <wyzelli@yahoo.com>
Re: Script to "rotate" the chars in a string. (Martien Verbruggen)
Re: stability of threads + interpreter performance <not@defined.com>
Re: stability of threads + interpreter performance <not@defined.com>
Re: stability of threads + interpreter performance <not@defined.com>
Re: tab delimitated file (Anno Siegel)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Jan 2001 09:14:32 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: ActivePerl Modules Installation Problems
Message-Id: <3A713FF8.147517E6@bbsrc.ac.uk>
Konstantin Chaus wrote:
>
> Hellow Everybody!
>
> I have a problem (see subj). I've downloaded the latest version of
> ActivePerl (www.activestate.com). There was a remark, that for correct work
> of ppm I need to download the new version of 'XML-Parser'. Without it when I
> tried to install any additional module (for Win32) I got an error that there
> (in module pakadge) wasn't any win32 version of this module. After
> installation the new ver of XML-Parser my PPM've stopped working.
[snip]
This is strange? I've recently downloaded 5.6.0 Active Perl, and PPM
works out of the box - no hacks needed, no nothing. Just as a thought -
did you remove your old installation of Perl before installing the new
one? Activestate's site contains warnings about installation problems
if you try to install over an older version.
You should also wipe out any old PPM files as they won't be compatible
with the new release.
Simon.
------------------------------
Date: Fri, 26 Jan 2001 08:37:29 GMT
From: jqcordova@my-deja.com
Subject: Best way to learn Perl?
Message-Id: <94rd09$7j7$1@nnrp1.deja.com>
Spent last couple of years building well-known e-commerce sites using
Open Source code. Used a lot of Perl and had to teach jr. programmers a
lot about Perl. Found out most effective way was the so-called Socratic
method of question/answer. So, put together a website www.codecity.com
to explore this approach to teaching Open Source. Hope to get some
feedback/participation from this group. Hope this is appropriate.
Jeff C.
www.codecity.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 08:42:38 GMT
From: "Brent Dax" <brentdax1_@_earthlink.net>
Subject: Built-in Function Questions
Message-Id: <2Mac6.630$OR1.81337@newsread2.prod.itd.earthlink.net>
Hash: SHA1
I'm writing a Perl-based UNIX shell. (I'm posting the code below in
case anyone wants to see it.) One of the things it has is a
customizable prompt--they can change the message. I'd like to add a
feature so that the prompt command could accept special "variables"
representing information like the current user or the current
directory. So, here are my two questions:
1. Is there a logical opposite of chdir()? That is, a function that
returns the current directory? (Couldn't find anything in the docs,
but who knows?)
2. What does getlogin() return? The login name? (The documentation
says that it's just like a C library call--one that I'm not familiar
with.)
3. Can anybody think of something else they might want to put in
their prompt? If so, can you tell me what I should call to get the
data for it?
For your drooling pleasure (yeah right), I've posted the incomplete
code below. It ain't pretty, but it does the job.
#!/usr/bin/perl -w
# psh version 0.1 by Brent Dax
# brentdax1@earthlink.net
# 1-26-2K1
# who cares if i corrupt the pureness of the #! or whatever?
use strict;
my ($code, $prompt);
$prompt="psh>";
print "psh version 0.1 by Brent Dax.\n" . `date` . "\n";
print $prompt;
while(<STDIN>) {
chomp($_);
if($_ eq "exit"||$_ eq "bye") { # special handling for exits
last;
} elsif(/prompt (.+)/) { # allows user to change the prompt
$prompt=$1;
} elsif(/cd (.+)/) { # uh...implements cd, duh...
chdir $1||warn "Unable to change directory to $1.\n";
} elsif($_ eq "#!") {
$code=undef; # if you did enter a shebang, we have to clear
out $code
$code .= $_ until(<STDIN> eq "!#\n"); # keep getting code on
STDIN until we get a reverse shebang
run $code;
#untested
} elsif(/(.+) #!/) { # "filename #!" loads "filename" for
execution
open(CODE, $1);
while(<STDIN>) {
$code .= $_ unless(/^#/);
#that unless thing: just to be nice, we're removing some
of the comments
#beforehand. this has the added benefit of killing the
shebang line.
}
close(CODE);
run $code;
#end untested
} else {
print `$_`; #just execute the stupid command and wait for
input
}
print "\n", $prompt;
}
print "Goodbye.\n";
sub run {
no strict; #turn off strict, cause it could screw with the code
fragment they just entered
eval shift; #run the stupid code
print <<END;
! psh: A code block returned the following error:
$@
END
if($@); }
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOnE4SbJgQ5JqNEGyEQLxUgCeMcTe6EsQcHJ/DOwVMy9YDmnOeWgAoMFP
QYVZN/vetb07ej3eRo7dKVW2
=7kup
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 26 Jan 2001 09:05:22 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Built-in Function Questions
Message-Id: <slrn972ffi.jr9.rgarciasuarez@rafael.kazibao.net>
Brent Dax wrote in comp.lang.perl.misc:
>
> I'm writing a Perl-based UNIX shell.
Well, it's your right.
> 1. Is there a logical opposite of chdir()? That is, a function that
> returns the current directory? (Couldn't find anything in the docs,
> but who knows?)
The Cwd module.
> 2. What does getlogin() return? The login name? (The documentation
> says that it's just like a C library call--one that I'm not familiar
> with.)
If it's a C library call, it's documented in section 3 of the Manual.
> 3. Can anybody think of something else they might want to put in
> their prompt? If so, can you tell me what I should call to get the
> data for it?
The output of any user-defined command? xterm escape sequences?
> For your drooling pleasure (yeah right), I've posted the incomplete
> code below. It ain't pretty, but it does the job.
Strange syntax. Lacks of robustness. Obsfuscated Perl syntax can easily
fool it.
Have you looked at the FAQ : "Is there a Perl shell?"
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 26 Jan 2001 09:06:23 GMT
From: "Brent Dax" <brentdax1_@_earthlink.net>
Subject: Re: Built-in Function Questions
Message-Id: <j6bc6.650$OR1.88320@newsread2.prod.itd.earthlink.net>
Hash: SHA1
Oops. I made the mistake of making big changes to the code without
testing them first. Aren't I clever?
Anyway, here's a better version. It now keeps a stack of old
external commands, but you can't use it yet. Running external
commands works, but the exec stuff isn't working--if anyone knows
why, please tell me. I get the distinct feeling it's something
really stupid, though.
One more thing--I discovered that cd is done by the shell the hard
way. If anybody knows any other commands the shell implements, let
me know so I can build them in.
- --Brent Dax
brentdax1@earthlink.net
#!/usr/bin/perl -w
# psh version 0.1 by Brent Dax
# brentdax1@earthlink.net
# 1-26-2K1
# who cares if i corrupt the pureness of the #! or whatever?
use strict;
my ($code, $prompt)=(undef, "psh>");
my @commands; #for later
sub run {
no strict; #turn off strict, cause it could screw with the code
fragment they just entered
eval $_[0]; #run the stupid code
print "! psh: A code block returned the following error: \n $@"
if($@); }
print "psh version 0.1 by Brent Dax.\n" . `date` . "\n";
print $prompt;
while(<STDIN>) {
chomp($_);
if($_ eq "exit"||$_ eq "bye") { # special handling for exits
last;
} elsif(/prompt (.+)/) { # allows user to change the prompt
$prompt=$1;
} elsif(/cd (.+)/) { # uh...implements cd, duh...
chdir $1||warn "Unable to change directory to $1.\n";
} elsif($_ eq "#!") {
$code=undef; # if you did enter a shebang, we have to clear
out $code
$code .= $_ until(<STDIN> eq "!#\n"); # keep getting code on
STDIN until we get a reverse shebang
run $code;
} elsif(/(.+) +#!/) { # "filename #!" loads "filename" for
execution
open(CODE, $1);
while(<STDIN>) {
$code .= $_ unless(/^#/);
#that unless thing: just to be nice, we're removing some
of the comments
#beforehand. this has the added benefit of killing the
shebang line.
}
close(CODE);
run $code;
} else {
system($_); #just execute the stupid command and wait for
input
push @commands, $_;
}
print "\n", $prompt;
}
print "Goodbye.\n";
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOnE927JgQ5JqNEGyEQKcLgCeJmdydVI8zCz9biNUUfO+eZXO2CEAnjYo
EkCOAXxBf9FVg+F4snkqjF2p
=cO61
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 26 Jan 2001 09:42:33 GMT
From: "Brent Dax" <brentdax1_@_earthlink.net>
Subject: Re: Built-in Function Questions
Message-Id: <dEbc6.689$OR1.97415@newsread2.prod.itd.earthlink.net>
Hash: SHA1
One more time. :^) This one functions pretty well--it'll run code
brought in from an outside file (using filename #!), or code entered
at the command line using
#!
code
!#
(Yeah, it's weird. So what?) Still working on using the command
stack and doing some sort of special variables in the prompt, though.
#!/usr/bin/perl -w
# psh version 0.1 by Brent Dax
# brentdax1@earthlink.net
# 1-26-2K1
# who cares if i corrupt the pureness of the #! or whatever?
use strict;
my ($code, $prompt)=(undef, "psh>");
my @commands; #for later
sub run {
no strict; #turn off strict, cause it could screw with the code
fragment they just entered
eval $_[0]; #run the stupid code
print "! psh: A code block returned the following error: \n $@"
if($@); }
print "psh version 0.1 by Brent Dax.\n" . `date` . "\n";
print $prompt;
while(<STDIN>) {
chomp($_);
if($_ eq "exit"||$_ eq "bye") { # special handling for exits
last;
} elsif(/prompt (.+)/) { # allows user to change the prompt
$prompt=$1;
} elsif(/cd (.+)/) { # uh...implements cd, duh...
chdir $1||warn "Unable to change directory to $1.\n";
} elsif($_ eq "#!") {
$code=undef; # if you did enter a shebang, we have to clear
out $code
$code .= $_ until(($_=<STDIN>) eq "!#\n"); # keep getting
code on STDIN until we get a reverse shebang
run $code;
} elsif(/(.+) +#!/) { # "filename #!" loads "filename" for
execution
open(CODE, $1);
while(<CODE>) {
$code .= $_ unless(/^#/);
#that unless thing: just to be nice, we're removing some
of the comments
#beforehand. this has the added benefit of killing the
shebang line.
}
close(CODE);
run $code;
} else {
system($_); #just execute the stupid command and wait for
input
push @commands, $_;
}
print "\n", $prompt;
}
print "Goodbye.\n";
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOnFGVbJgQ5JqNEGyEQIgqwCfcazhMLNiCwdD6S54BqwULIG3rHgAoPfc
3YoqTdQOmpvAQPFykzEdGnMN
=t3aJ
-----END PGP SIGNATURE-----
------------------------------
Date: 26 Jan 2001 09:56:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Comparing multiple values
Message-Id: <slrn972idl.q5.abigail@tsathoggua.rlyeh.net>
Craig Berry (cberry@cinenet.net) wrote on MMDCCIV September MCMXCIII in
<URL:news:t719n74kcfuv79@corp.supernews.com>:
'' datastar@my-deja.com wrote:
'' : I can say:
'' :
'' : if ($somevar==3) { } # do something
'' :
'' : ...but what if I want to test if $somevar equals 3,4,8 or 9?
''
'' if (grep { $_ == $somevar } qw(3 4 8 9)) {
''
unless ($x ** 4 - 24 * $x ** 3 + 203 * $x ** 2 - 708 * $x + 864) { ... }
which can be optimized to:
unless (((($x - 24) * $x + 203) * $x - 708) * $x + 864) { ... }
(Using $x instead of $somevar for line length reasons.)
Abigail
--
split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Fri, 26 Jan 2001 10:43:40 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Dealing with x1b character
Message-Id: <3A7153DE.1164AA14@free.fr>
hparks@my-deja.com wrote:
> Some debugging showed the
> program was exiting when an escape character (hex 1B) was encountered.
Nothing in your published code can make your program exit because of an
escape character. The only thing I can imagine is that your regexp
doesn't match because of this extra character in the part of the line
you are matching (for example, between the --- and the header number).
If I'm wrong, the error is probably somewhere else in the yet
unpublished part of your code ?
Jerome.
------------------------------
Date: Fri, 26 Jan 2001 08:12:15 GMT
From: "Brent Dax" <brentdax1_@_earthlink.net>
Subject: Re: Error Message
Message-Id: <zjac6.548$OR1.73548@newsread2.prod.itd.earthlink.net>
"Dustin" <dfreeman@rathis.com> wrote in message
news:t70icjemiog4d0@corp.supernews.com...
> Brent,
>
> I am running NT4 on my local system.
> The was no metion of fork() in any documentation that a got with the
script.
> What is it? This is only the 5th script that i have set up and I have
been
> doing pretty good until now.
fork() is a function that basically splits one program into two. Each copy
of the program can then do one task without worrying about what the other
copy is up to.
More to the point, I may have been wrong about fork() not working: the
ActiveState documentation does allude to fork() being imperfectly emulated.
What version of perl are you using? (try: perl -v) Does your script even
use fork()? (search the source for a call to the fork() function) When are
you getting this error, before or after your script starts? (find some
clever way of figuring it out--for example, write out to a file the letter
"x" right away when the script starts, and see if the file contains the
letter "x" or not. code example below)
#insert this just below the use whatever; stuff at the top of the program.
open (GAGA, ">>gaga.txt");
print GAGA "x";
close (GAGA);
#run the script once, then check gaga.txt and see if there are any x's in
it.
#you can even put this in a few places throughout the program and count
#the x's--just make sure you empty out the file between runs.
#make sure you delete this stuff before you use the code in an actual
application,
#or you'll suffer performance losses.
------------------------------
Date: Fri, 26 Jan 2001 00:17:55 -0800
From: Kira <callgirl@la.znet.com>
Subject: Re: FAQ 1.7: Is Perl difficult to learn?
Message-Id: <3A7132B3.FFB9B5B0@la.znet.com>
PerlFAQ Server wrote:
(various snippage)
> Is Perl difficult to learn?
> No, Perl is easy to start learning -- and easy to keep learning.
> Things that make Perl easier to learn: Unix experience, almost any kind
> of programming experience, an understanding of regular expressions, and
> the ability to understand other people's code.
"Ability To Understand Other People's Code"
uh huh...
All of which is said in this FAQ, is quite true. However,
a "Godzilla However" for you.
However, if beginners truly want to learn Perl, my direct
experience is to start with Perl 4 and move to Perl 5. There
is a good reason for this. Perl 4, for the most part, is
still written in plain English, most can understand. With
the advent of Perl 5, a move is in motion towards deliberate
obfuscation, a move leading Perl into a language the best
of CIA spooks would be challenged to decipher. Modern
Perl now better resembles Egyptian Hieroglyphics. Adding
to this significant language barrier, techno-geeksters
take delight in writing Perl code with an intent of making
it completely unreadable to any but the most geekster of
techno-geeks. This notion of extreme obfuscation is spreading
like wildfire and seem as much a fashion rage today as is
breast reduction and orange colored hair, both of which,
I personally have no need, especially the former.
As a well seasoned but not sagging educator, a foundation
of education, of learning, is just that; a good foundation.
Egyptians build pyramids with broad substantial foundations.
Learning a bit of Perl 4 will help to establish a broad
foundation upon which to build Perl 5 knowledge.
Learning Perl 5 and disregarding learning Perl 4, is to
build your pyramid of knowledge upside down. Get the
picture? Pretty shakey business toppled by the slighest
of camel sneezes.
So, if you elect to learn only Perl 5, you will need to
develop a mindset of being a maxed out zoom dweebie ultra
nerdy techno-geekster symbolist who cannot speak English,
especially Plain English, my favorite.
Learn your abc's first, then worry about fat arrow and
skinny percentage sign symbolist lingo.
Good FAQ but sorely lacking in educational value and
good educational technique.
Godzilla!
Kiralynne Schilitubi
Professor of English
University of California at Riverside
------------------------------
Date: Fri, 26 Jan 2001 10:43:27 GMT
From: lou@visca.com (Lou Hevly)
Subject: Re: Hash of hash of arrays problem
Message-Id: <3a7154aa.311897097@news.wanadoo.es>
Jonathan Feinberg <jdf@pobox.com> wrote:
>lou@visca.com (Lou Hevly) writes:
>
>> However, when I make the values of %data into array refs, so as to be
>> able to push more data onto them later, I get a reference to the
>> *same* hash as my %domains hash values:
>>
>> my %data = (
>> du_w => ['Disk Usage: Web'],
>> du_m => ['Disk Usage: Mail'],
>> tot_du => ['Total Disk Usage'],
>> );
>
>Now $data{du_w} contains a reference to an anonymous array, right?
>That reference is essentially a pointer to a memory location (for the
>purposes of this explanation, that's true enough). When you copy
>%data into a new anonymous hash, you're not constructing new anonymous
>arrays; you're copying those pointers into the new hash.
<snip rest of excellent explanation>
>I hope this helps!
Very much so! I just wasn't looking deeply or clearly enough into what
I was doing. I've changed the code to put the anonymous array creation
within the loop and all is well:
my %domains;
for (grep !/^\.\.?/ && -d, readdir D) {
$domains{$_} = {
du_w => ['Disk Usage: Web'],
du_m => ['Disk Usage: Mail'],
tot_du => ['Total Disk Usage'],
};
}
Thanks again. This list is the greatest!
--
All the best,
Lou Hevly
lou@visca.com
http://www.visca.com
------------------------------
Date: 26 Jan 2001 08:37:53 +0000
From: nobull@mail.com
Subject: Re: How do you backspace(back delete) on console?
Message-Id: <u9hf2mhd5u.fsf@wcl-l.bham.ac.uk>
montep@hal-pc.org (Monte Phillips) writes:
> Subject: How do you backspace(back delete) on console?
This appears to be a question about your (unspecified) console device
not Perl.
> Backspace print using \b is fine except I need to backspace on the
> display screen. Print a character then backspace over it and print
> another character on the same spot.
What is the significance of 'except' in the above? Don't answer that,
this has nothing to do with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 26 Jan 2001 10:29:28 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How to do this regular expression?
Message-Id: <slrn972kc6.2q0.bernard.el-hagin@gdndev25.lido-tech>
On 25 Jan 2001 22:16:50 GMT, Eli the Bearded <elijah@workspot.net> wrote:
>In comp.lang.perl.misc,
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote:
[snip]
>> #requires 5.6.0
>> perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
>
>Clever. But it fails if JAPH is a program on your path.
It's a risk I've learned to live with.
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Fri, 26 Jan 2001 08:14:22 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Iterating through matches to a regexp ?
Message-Id: <3A7130E1.F78C9FD4@free.fr>
Jerome Abela wrote:
> 'aaabbb'=~m/(a+b+)(?{push @res, $1})(?!.|$)/g;
> print join('/', @res);
>
> The result is: aaabbb/aaabb/aaab/aabbb/aabb/aab/abbb/abb/ab
m/(a+b+)(?{push @res, $1})^/g is enough. No need to use (?!).
Jerome.
------------------------------
Date: Fri, 26 Jan 2001 10:56:39 +0100
From: "Michael Schlueter" <Michael.Schlueter@philips.com>
Subject: Re: Know Perl? Help a poor hack out with if-else statement
Message-Id: <3a7149d9$0$8778$4dbef881@businessnews.de.uu.net>
Dear Eroth (?),
There are several ways to do it. It depends on what you want to do with the
new variable. Please have a look on the topic "scopes" within, e.g.
"Learning Perl" (O' Reilly).
1) Just have the new variable within a sub and nowhere else again
#!/usr/bin/perl -w
use strict; # do it and watch the error messages while
experimenting with scopes
test();
print $only_sub; # this is a new variable, different from the one in the
sub
sub test {
my $only_in_sub="some data"; # this new variable springs into
existence
print $only_in_sub; # will print its contents
} # this new variable is
removed
2) Modify a global variable (Do not do it that way, for your own sake.)
#!/usr/bin/perl -w
use strict;
my $global_var;
test();
print $global_var; # same variable as in the sub
sub test {
$global_var="some data"; # use the global variable, because it
already exists
print $global_var; # will print its contents
} # this new variable is
removed
3) Use return values (I recommend this)
#!/usr/bin/perl -w
use strict;
my $var;
$var=test();
print $var;
sub test {
my $local_var="some data"; # create $local_var
print $local_var;
return $local_var;
} # remove $local_var again (done by Perl)
The best way to see the differences, in my oppinion, is to run these
programs with the Perl debugger, e.g.
perl -d test.pl
Use h for the help-menue, x $var to output all information on this variable
(memory address, contents), use l to list lines, use b <line number> do set
a breakpoint.
Michael Schlueter
------------------------------
Date: Fri, 26 Jan 2001 08:19:46 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: LWP/ Web Login Advice Needed
Message-Id: <slrn972cq2.i8a.rgarciasuarez@rafael.kazibao.net>
Sara Dunn wrote in comp.lang.perl.misc:
>
> There is a remote Web service that people will log into which
> requires a userid and password. I want to protect that password
> and instead have them log into a local page on a local server
> using a local userid and password
> which is , of course, different from the set used to get into
> the remote service. Then once authenticated at the local site
> my CGI will pass the real userid/password combo onto the remote
> site and redirect the user.
What method do this remote service use for login ? Cookies ? HTTP
authentication ? No matter, I doubt that the process you're describing
is possible, with or without Perl. You can authenticate your local
server into the remote service, but this will by no means authenticate
the end-user.
An example with cookies : your local CGI script, acting as a browser for
the remote service, will receive some authenticating cookie. To
authenticate the end-user, his browser should also receive this cookie.
But your CGI script can't pass it -- because the local and remote
services are on different hosts and domains.
What you want looks like an HTTP proxy server. It's possible to program
an HTTP proxy with Perl; but you should probably look at existing
proxies and decide if one of them can do this job or can be modified to
do it.
--
Rafael Garcia-Suarez
<ad> A proxy to debug web applications with cookies:
http://rgarciasuarez.free.fr/perl/biscuit.html </ad>
------------------------------
Date: Fri, 26 Jan 2001 08:37:44 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Precision? (was: Perl is bad at (very) simple math!)
Message-Id: <3a713757.2de2$209@news.op.net>
Keywords: Menzies, advise, broody, obfuscatory
In article <94qd71$di5$1@nnrp1.deja.com>,
Daniel Pfeiffer <occitan@esperanto.org> wrote:
>$ perl -e 'print 1e9|1,"\n", 1e10|1,"\n", 1e15-1,"\n", 1e15+1,"\n"'
>1000000001
>4294967295
>999999999999999
>1e+15
>
>which seems to suggest that 1e9 is the biggest power-of-ten-integer
>while 1e15 seems to be the biggest integrally precise
>power-of-ten-float.
That makes sense. You have 32-bit integers, so the largest
representable integer is 2^32-1 = 4294967295 and the largest
representable integer power of 10 is 1000000000.
Your floating point numbers are 64 bits, most likely represented in
the IEEE format. A 64-bit IEEE floating-point number has a sign bit,
an 11-bit exponent, and a 52-bit mantissa. The largest number
representable has a mantissa of
1.1111111111111111111111111111111111111111111111111111
(that is, 2 - 2**(-52) = 1.99999999999999977796; the inital "1." is
implicit) and an exponent of 2047, so it's equal to
(2-2**(-52))*(2**2047) = 1.79769313486232e+308
The largest exactly representable power of 10 is a little trickier.
What we really need is to find the largest power of 5 that can be
represented exactly; then we can adjust the exponent appropriately; if
5**n can be represented exactly, then 10**n is just the same, except
that the exponent is larger by n.
5**23 = 11920928955078125 =
101010010110100000010110001111110000101001010111101101, which is too
long. (It's 54 bits, 53 without the leading 1, and we only have room
for 52.)
However, 5**22 = 2384185791015625 =
1000011110000110011110000011001001101110101011001001.0, which yields a
mantissa of 0000 11110000 11001111 00000110 01001101 11010101 10010010
(remember the leading 1 is implied) and an exponent of 50. The
largest power of 10 will have the same mantissa and an exponent of 72.
The 64-bit floating-point representation is:
SIGN EXPONENT MANTISSA
0 10001001000 0000111100001100111100000110010011011101010110010010
(The high bit set in the exponent indicates that it's non-negative.)
Breaking this up into bytes gives:
01000100 10000000 11110000 11001111 00000110 01001101 11010101 10010010
In base 10, the bytes are:
68 128 240 207 6 77 213 146
OK, let's give that a whirl:
# Only use 'reverse' if your computer is little-endian
$d = unpack "d", pack "C*", reverse (68, 128, 240, 207, 6, 77, 213, 146);
printf "%.20f\n", $d;
and our program prints the largest exactly representable power of 10:
10000000000000000000000.00000000000000000000.
Wah-lah, and rather bigger than what you suggested.
Why's that? Because your test was looking for something else: Where
does the floating-point format precision become coarser than 1? It
occurs for when the least significant bit in the mantissa has a value
greater than 1; since the mantissa is 52 bits wide, this occurs when
the exponent exceeds 52. (In the example above, we were able to
represent 10^22 all right, but the next larger number after that is
10000000000000002097152 because the large exponent (70) makes the
least significant bit of the mantissa worth 2097152 instead of only 1.)
Putting together a number with an exponent of 52 and a mantissa of all
1's yields:
$d = unpack "d", pack "C*", reverse (67, 63, 255, 255, 255, 255, 255, 255);
printf "%.2f\n%.2f\n%.2f\n%.2f\n", $d-1, $d, $d+1, $d+2;
9007199254740990.00
9007199254740991.00
9007199254740992.00
9007199254740992.00
$d+1 works correctly, but that's the end of the line. After that, the
LSB is worth 2 instead of 1, so ($d+1)+1 loses the extra 1 to
round-off error.
The largest power of 10 less than this amount is 1000000000000000 =
10**15, as you discovered. But you got lucky. Your program, like many
that involve floating-point numbers, has committed a round-off
error---Perl uses a default format of '%15g' when printing
floating-point numbers. Even if your computer could have represented
10**16 without loss of precision, your program might not have found
out, since it was formatting the numbers with scientific notation once
they got longer than 16 digits.
Now, why does Perl use a default format of %15g? Because your C
compiler defines a macro called DBL_DIG to be 15. Why does it define
it to be 15? Because 10**15 is the largest power of 10 that your
computer can represent without loss of precision.
>But is this universally true, or does it depend on the underlying
>architecture and/or C compiler?
Certainly on the architecture, and possibly on the compiler. Nothing
stops the compiler from implementing its own floating-point arithmetic
routines in software to any precision it desires.
>And if so, what is the best way to find out?
Your way looks a lot easier than mine, but easier still is to look up
DBL_DIG in <float.h>. DBL_DIG might conceivably lie, but if it does
your method won't work anyway. (Mine is even less robust, since it
depends on the internal details of the floating-point format. On the
other hand, you can be absolutely sure of the results, if you have
enough understanding.)
>thanks -- Daniel
I guess this is one for the more-than-you-wanted-to-know file.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Fri, 26 Jan 2001 10:36:19 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Problem with Tie::StdHash / FETCH ??
Message-Id: <3A715224.5E4C5769@free.fr>
nexus6_kills@yahoo.com wrote:
> The problem that I am encountering is shown in the example
> file below (sorry for the length, but it is as short as I
> could make it). In "package main", I have listed the seven
> cases which I would like to make work. The last two cases
> do not work. I would like to know why they don't work. I
> understand that it has something to do with copy, but some
> help would be appreciated.
You are lucky that some of your cases work, because what your code is
doing is really strange !
> sub new
> {
> my %retHash;
> tie %retHash, $className, $self;
> return bless \%retHash, $className;
This part of your code is probably the source of your problems. When you
tie() a variable, it is bound to an instance of the specified class. The
class instance manages the internal state and behaviour of the tied
variable. As this is a case of tied hash, you tried to mix them, and the
same variable is both the tied variable and blessed with the same class
as its implementation counterpart. So, depending on the way you call a
member method (on the tied one or just on the blessed one), a member
value acces is redirected or not through the tie methods.
The behaviour of such a construction is probably not defined in the
Perl5 language, and you should not use it. I think you are right when
you say it's a bug, but I think the correct fix is to issue an error
when a tied hash is trying to be blessed.
Jerome.
------------------------------
Date: Fri, 26 Jan 2001 09:35:26 GMT
From: Hessu <qvyht@iobox.fi>
Subject: regexpr as condition
Message-Id: <3A71450B.AFE8CFE7@iobox.fi>
Newbie here wondering if this is possible
Can I use regular expressions in loops or elsewhere like this:
do block 0 or more times:
*{ BLOCK } condition;
*{ BLOCK }
----------
do block 1 or more times
+{ BLOCK } condition (like do..while)
----------
do block 1 or 0 times
?{ BLOCK } condition
----------
do block at least n and at most m times
{n,m} { BLOCK }
----------
if block's result is true straight forward
otherwise continue like block wasn't never
done
reset{BLOCK }
------------------------------
Date: Fri, 26 Jan 2001 18:02:42 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <KCac6.2$tk5.408@vic.nntp.telstra.net>
"Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
news:slrn972b40.i8a.rgarciasuarez@rafael.kazibao.net...
> James Kufrovich wrote in comp.lang.perl.misc:
> >
> > I just put together a small script (at the bottom there) that will
> > rotate the characters in a string (supplied on the command line) and
print
> > the resulting string out, both forwards and backwards. In other words,
> > giving the program the string "funky" will produce the following output:
>
> Another alternative approach, uses substitutions :
>
> #!/usr/local/bin/perl -l
> $_ = shift;
> my $n = length;
> for my $i (1..$n) { print; s/^(.)(.*)/$2$1/ }
> $_ = join '', reverse split //;
> for my $i (1..$n) { print; s/^(.)(.*)/$2$1/ }
>
I like that.
with this solution, the second half reverses the word and then rotates in
the same direction (not that that is wrong)
Changing to
for my $i (1..$n) { print "$_\n"; s/^(.)(.*)/$2$1/ }
for my $i (1..$n) { print "$_\n"; s/^(.*)(.)/$2$1/ }
Reverses the direction of the rotate whilst the word is still in order.
Additionally adding 1 to $n in the second half finishes printing the
restored word.
for my $i (1..$n) { print "$_\n"; s/^(.)(.*)/$2$1/ }
for my $i (1..$n+1) { print "$_\n"; s/^(.*)(.)/$2$1/ }
funky
unkyf
nkyfu
kyfun
yfunk
funky
yfunk
kyfun
nkyfu
unkyf
funky
Wyzelli (still havin fun...)
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Fri, 26 Jan 2001 19:31:25 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <slrn972det.tip.mgjv@martien.heliotrope.home>
On Thu, 25 Jan 2001 23:18:14 GMT,
James Kufrovich <eggie@REMOVE_TO_REPLYsunlink.net> wrote:
>
> funky
> unkyf
> nkyfu
> kyfun
> yfunk
> yknuf
> knufy
> nufyk
> ufykn
> fyknu
Yet another one:
#!/usr/local/bin/perl -wl
$r = reverse $s = shift;
print $s and $s .= substr $s, 0, 1, "" for 1 .. length $s;
print $r and $r .= substr $r, 0, 1, "" for 1 .. length $r;
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Fri, 26 Jan 2001 10:30:27 GMT
From: "Koen Bossaert" <not@defined.com>
Subject: Re: stability of threads + interpreter performance
Message-Id: <7lcc6.152$Ec5.991@nreader1.kpnqwest.net>
"Damian James" <damian@qimr.edu.au> wrote in message
news:slrn96tl36.kvq.damian@puma.qimr.edu.au...
> Thus spake Koen Bossaert on Wed, 24 Jan 2001 12:03:19 GMT:
> >...
> >
> >My problem is following : I need a script that connects to a few servers
> >every so many seconds to get some information. Then it uses that
information
> >in some calculations and the result is stored in memory. In the mean
time
> >it should listen at a certain port to provide clients that connect with
the
> >latest results from the calculations. I thought 2 threads could be the
> >solution because they share the same memory.
> >
>
> Use an RDBMS and separate processes. Why try to keep state in memory?
Because speed is a big issue I wanted to avoid as much DB/disk/network
access as possible.
> What
> happens when your UPS dies because the air-con serviceman has plugged his
> welder into the machine room power circuit. Have the polling processes
> update the data, then let the server process serve it out.
If the UPS dies the data isn't relevant anymore in this situation
Koen
------------------------------
Date: Fri, 26 Jan 2001 10:49:19 GMT
From: "Koen Bossaert" <not@defined.com>
Subject: Re: stability of threads + interpreter performance
Message-Id: <PCcc6.154$Ec5.1245@nreader1.kpnqwest.net>
"Dan Sugalski" <dan@tuatha.sidhe.org> wrote in message
news:hUEb6.154440$P82.18692973@news1.rdc1.ct.home.com...
> Koen Bossaert <not@defined.com> wrote:
> > My problem is following : I need a script that connects to a few servers
> > every so many seconds to get some information. Then it uses that
information
> > in some calculations and the result is stored in memory. In the mean
time
> > it should listen at a certain port to provide clients that connect with
the
> > latest results from the calculations. I thought 2 threads could be the
> > solution because they share the same memory.
>
> That's a reasonable problem for threads. Given threads instability (and
> generally speaking, even if threaded perl was rock solid, using threads
> tends to make things rather more interesting than you might like) what
> I'd do instead is to split this into two processes--one that handles the
> connection to the servers, and another that handles the connections
> looking for info. Have your server check process connect to the data
> serving process when it's got new data and spit out the new info to
> it.
That's indeed a nice solution, thanks.
Koen
------------------------------
Date: Fri, 26 Jan 2001 11:00:25 GMT
From: "Koen Bossaert" <not@defined.com>
Subject: Re: stability of threads + interpreter performance
Message-Id: <dNcc6.156$Ec5.1239@nreader1.kpnqwest.net>
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7g0i8wvg5.fsf@home.sysarch.com...
> >>>>> "KB" == Koen Bossaert <not@defined.com> writes:
>
<snip>
> where did you get this idea? all callbacks in event.pm are just perl
> code. you can store data anywhere you want. many complex server (much
> bigger than your needs) use event.pm.
<snip>
> you could do that in event.pm in a few hours. you don't have multiple
> memories in any perl program. you might have thread private data but
> event.pm data can be global with no issues. where did you get this
> misconception?
Uh, I'm sorry, I should have read the manpage better.
So if I want to solve this with Event.pm I guess it should look like :
...
my $watcher = Event->timer(interval => $seconds, cb => \&call_back_timer);
my $watcher2 = Event->idle(cb => \&call_back_idle);
loop();
sub call_back_timer {
do_poll();
# no unloop
}
sub call_back_idle {
my $client = $socket->accept(); # no infinite while
process_request(...);
...
# no unloop
}
Is this the right way to do it?
I saw your name in the acknowledgements, nice work.
Koen
------------------------------
Date: 26 Jan 2001 08:28:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: tab delimitated file
Message-Id: <94rcfc$7ko$1@mamenchi.zrz.TU-Berlin.DE>
Bier <yukon_jach@yahoo.com> wrote in comp.lang.perl.misc:
>I want to pass a tab delimitated file to a Perl program, and am unsure of
>how to proceed.
>
>The file is made up of many rows each containing several columns of data, of
>varying length. The first row contains the column headings. Only certain
>columns of are interest, for example columns 1, 2, 4, 6, and 9. Starting at
>the second row I want read the appropriate columns and assign each to a
>particular variable. The data will processed and passed to another file. The
>program would then proceed with the third row and so forth.
>
>I would like to learn how to read only the desired columns starting on the
>second row.
To skip the first row (or any row) just read it and go ahead, ignoring
the line.
To select columns, learn about split (perldoc -f split) and array slices
(perldoc perldata, I guess).
One of the CVS modules may be of help too (they deal with tab separated
columns as well).
Anno
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 148
**************************************