[13744] in Perl-Users-Digest
Perl-Users Digest, Issue: 1154 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 22 17:05:29 1999
Date: Fri, 22 Oct 1999 14:05:11 -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: <940626310-v9-i1154@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 22 Oct 1999 Volume: 9 Number: 1154
Today's topics:
Re: authentification with perl/cgi? <james_peregrino@harvard.edu>
Re: Can I use flock as lever to create reliable unique <rootbeer@redcat.com>
Re: Code example help? <rootbeer@redcat.com>
Re: define global variables <rootbeer@redcat.com>
Re: exiting non-zero at end of perl -[np] <rootbeer@redcat.com>
Re: exiting non-zero at end of perl -[np] <aqumsieh@matrox.com>
Re: Expr or block as 1st param: Compiler magic needed? <lr@hpl.hp.com>
Re: File "cgi-lib.pl" not found in @INC? <AgitatorsBand@yahoo.com>
How can I join two hashes? <troja2977@my-deja.com>
Re: How can I join two hashes? <newsposter@cthulhu.demon.nl>
Re: How can I join two hashes? (Ilya Zakharevich)
Re: How to cut away decimals <sswaminathan@micron.com>
Re: How to round a number? <sswaminathan@micron.com>
Re: How to round a number? <skilchen@swissonline.ch>
Re: How to round a number? <skilchen@swissonline.ch>
Re: I'd like to know what are those CGIs and ASPs <james_peregrino@harvard.edu>
Re: in need of example... <AgitatorsBand@yahoo.com>
Re: mv file routine in perl for NT & Unix? <rootbeer@redcat.com>
Re: Need for Speed - Perlcompiler? <aqumsieh@matrox.com>
Re: New short cut assignment operators? (Craig Berry)
Re: New short cut assignment operators? <rootbeer@redcat.com>
Re: New short cut assignment operators? <gellyfish@gellyfish.com>
Re: New short cut assignment operators? <lr@hpl.hp.com>
Re: Newbie needs help with script! Should be easy for a <lr@hpl.hp.com>
Re: Perl and shadow passwords (Alan Curry)
Re: Perl Exam Beta Testers Required - How good are you? (Tad McClellan)
Please help! <aerial@online.no>
Re: Please help! <marcel.grunauer@lovely.net>
Re: Please help! (Alan Curry)
Re: PostgreSQL interfaces (Michael Budash)
seeking past 4GB <hal_mounce@amdahl.com>
Re: stealing the news: how hard can it be? <michael@cermak.com>
Re: Unlink <sswaminathan@micron.com>
Re: Unlink <rootbeer@redcat.com>
URGENT: Adding a AUTO-Email to Matt Writtes FFA Links (Max S.)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Oct 1999 15:34:25 -0400
From: James Peregrino <james_peregrino@harvard.edu>
Subject: Re: authentification with perl/cgi?
Message-Id: <x7vh7zb35q.fsf@bert.dce.harvard.edu>
Alexander Knack <ak@dasburo.de> writes:
> hi,
> i want a perl-CGI application to send an authorisationrequest to the
> client.
> i don't want to create a .htaccess file or something like this - the
> perlscript
> should handle the authentification. my problem is: i don't actually know
> how
> to do this.
[chomp]
> use CGI;
Good! I'd recommend at your stage in the game instead:
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
> my $uid = $ENV{REMOTE_USER};
> my $passwd = $ENV{REMOTE_PASSWD};
Nope!
REMOTE_USER is set after a successful Basic Authorization exchange.
There is no "REMOTE_PASSWD".
Key Point: As a CGI programmer, you don't have access to what is
passed to you via the pop up authentication dialog box. As a CGI programmer
you can make the box pop up, but it doesn't do you any good.
You have these options:
1) use a form as your login screen
2) Or get the code to Apache & modify it to get that password (yikes!)
3) Or go back to the traditional .htaccess set up.
-James
--
James Peregrino
Harvard Div. Continuing Education
------------------------------
Date: Fri, 22 Oct 1999 14:04:28 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Can I use flock as lever to create reliable unique cookie values?
Message-Id: <Pine.GSO.4.10.9910221358220.29843-100000@user2.teleport.com>
On Fri, 22 Oct 1999, Ben Blish wrote:
> But the flock docs don't say what flock returns,
> if anything, when an attempt to lock is made.
Should be true for success, false upon failure. Not unlike unlink, open,
close, opendir, stat, lstat, dbmopen, dbmclose, closedir, truncate, chown,
chmod, utime, chroot, link, rmdir, rename, and maybe one or two others.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 22 Oct 1999 13:57:17 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Code example help?
Message-Id: <Pine.GSO.4.10.9910221352530.29843-100000@user2.teleport.com>
On Thu, 21 Oct 1999, Trent wrote:
> # Filename and parameters from query
> $querystring = $ENV{'QUERY_STRING'};
> ($directory) = split(/\s*\,\s*/,$querystring,1);
Don't do this. Use a module, such as the CGI module. You're not even doing
it right. :-P
> $directory = "../$directory";
The CGI spec doesn't specify which directory will be the current working
directory when a CGI program is started.
http://hoohoo.ncsa.uiuc.edu/cgi/
It may be the root directory, the server's working directory, the home
directory for user nobody, the home directory for root, the directory the
program is stored in, the directory the server is stored in, the base
cgi-bin directory, the /tmp directory, a directory you don't have access
to from the shell, a directory named after an annoying character from
Saturday Night Live, a directory chosen at random, or some other
directory.
A CGI program which uses a relative path before chdir()ing to a
non-relative path is in a state of sin.
> opendir(DIR,$directory);
As with open(), you should check the return value from opendir().
> @files = grep(/\.asc/,readdir(DIR));
Could you have a file called 'fred.asc.jpeg'?
> open(READ,$file);
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> chop ($field_names = <READ>);
You may want chomp here.
Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 22 Oct 1999 13:47:29 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: define global variables
Message-Id: <Pine.GSO.4.10.9910221344560.29843-100000@user2.teleport.com>
On Thu, 21 Oct 1999, Tim & Barbara Aldrich wrote:
> I am aware of my and local for defining local variables. If I don't use
> either of these ... does that make it a global variable.
It's more general than that. If it's not a my() variable, it's a global.
Even if you've used local(), it's a global!
If this seems confusing, don't use local(). :-)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 22 Oct 1999 12:06:31 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: exiting non-zero at end of perl -[np]
Message-Id: <Pine.GSO.4.10.9910221205110.29843-100000@user2.teleport.com>
On Fri, 22 Oct 1999 jrw32982@my-deja.com wrote:
> What do people find the book good for?
>
> I've always found the online doc hard to use.
Gee, if you're going to answer your own questions, that takes the fun out
of it for the rest of us! :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 22 Oct 1999 15:02:11 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: exiting non-zero at end of perl -[np]
Message-Id: <x3yg0z38bik.fsf@tigre.matrox.com>
jrw32982@my-deja.com writes:
> entry. But to get to any entry for a specific function in the perl
> html doc takes several clicks, so I usually find it easier to just look
> it up in the Camel.
Use perldoc.
--Ala
------------------------------
Date: Fri, 22 Oct 1999 12:41:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Expr or block as 1st param: Compiler magic needed?
Message-Id: <MPG.127a5db13d75b71698a102@nntp.hpl.hp.com>
In article <3810ACC2.A921BFCF@midnightbeach.com> on Fri, 22 Oct 1999
11:28:18 -0700, Jon Shemitz <jon@midnightbeach.com> says...
> Larry Rosler wrote:
> > I hate to reward you for submitting the identical post twice in two
> > days. But I thought the question was instructive the first time I saw
> > it, and hadn't had time to put together and test a solution. So here
> > goes anyway. Next time, please show a little more patience.
>
> I'm sorry! I really am. I didn't notice that I was reposting only a day
> after the first post: sometimes my time sense is based more on how often
> I stop to check mail and news than on how often I stop to sleep.
It was two days after. Sorry. Still...
...
> > > returned a simple boolean scalar, rather than a list of all matches.
> >
> > In scalar context, grep() returns the number of matches, not the list of
> > all matches.
>
> I know that that's the effect - but is that what 'really' happens?
> Reverse engineering, I assume that there is only one grep primitive,
> which always returns a list, and the scalar context pretty much comes
> down to slapping an implicit "scalar" in front of the grep, to get the
> list length.
There are simple ways of investigating such conjectures without looking
at the compiler source.
#!perl -w
use strict;
use Benchmark;
my @data = ( 0 .. 9999 );
timethese(1 << (shift || 0), {
Array => sub { my $x = my @a = grep /0/ => @data },
List => sub { my $x = () = grep /0/ => @data },
Scalar => sub { my $x = grep /0/ => @data },
});
__END__
Benchmark: timing 1024 iterations of Array, List, Scalar...
Array: 46 wallclock secs (44.89 usr + 1.06 sys = 45.95 CPU)
List: 44 wallclock secs (43.19 usr + 1.00 sys = 44.19 CPU)
Scalar: 23 wallclock secs (23.16 usr + 0.00 sys = 23.16 CPU)
So scalar grep indeed does less work than list grep. Some feel strongly
that the same sort of optimization should be applied to map in void
context (not to generate the result list at all), but that hasn't
happened yet.
> > Here is a simple single function that does what you want. I refuse to
> > name it with jaggy caps, though. Those belong to Java, not here.
>
> while (unconverted) {print "Perl culture.\n";}
> - but though in my younger days I was a big fan of alllowercase, I've
> really come to think that MixedCase is much more legible. I actually
> think the javaStyle is anAbomination and hateTheWayYouHaveTo use a
> stupid convention to use Java class libraries; anyExpr and anyBlock were
> artifacts of splitting my first any into two pieces. But that's
> irrelevant.
What about all_lower_case? Easy on the eyes and the brain.
The argument against mixedCase is twofold: esthetically it is ugly; for
non-native speakers of English it is hard to decipher.
The argument for mixedCase is nonexistent. IMO.
In my Perl programs, I give special visual semantics to
Leading_upper_case names: significant global variables. I haven't used
Title_Case because it still looks jaggy, though more legible with the
underscores.
> > print any_expr_or_block(qw(foo foobar)), "\n";
> > print any_expr_or_block(qw(foo baz)), "\n";
> > print any_expr_or_block(sub { /foo/ }, qw(foobar)), "\n";
> > print any_expr_or_block(sub { /foo/ }, qw(baz)), "\n";
>
> Thanks, that's actually pretty similar to my first any(), which gives me
> warm fuzzies. However, grep and map let you say either of
>
> grep /foo/, @bar
> grep {m/foo/} @bar
>
> and that's the syntax that I was unable to get with my any().
No one has yet shown that it is possible to define the right prototype
to accomplish this.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 22 Oct 1999 20:57:28 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: File "cgi-lib.pl" not found in @INC?
Message-Id: <Yc4Q3.1071$LR3.183437@news.shore.net>
KernelKlink@webtv.net wrote:
: When following the recommendation above,does the cgi-lib.pl file still
: need to be present along with CGI.pm?
No. The functionality is included in CGI.pm.
: Also, is ANY script that is a
: valid usable script with cgi-lib.pl going to be usable with "use CGI
: qw(:cgi-lib);" ?
Should be. I found a minor bug in CGI.pm's emulation mode about a year ago
(basically,
&ReadParse;
$foo = '';
$in{'bar'} = $foo;
would not overwrite the value of $in{'bar'} that was passed to the
script) but Lincoln's probably fixed that by now.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Fri, 22 Oct 1999 19:20:57 GMT
From: Ron Seifenberger <troja2977@my-deja.com>
Subject: How can I join two hashes?
Message-Id: <7uqdek$c39$1@nnrp1.deja.com>
Hello,
is there a possibility to join two hashes?
Thanks,
Ron
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 22 Oct 1999 19:39:37 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: How can I join two hashes?
Message-Id: <7uqehp$9tr$1@internal-news.uu.net>
Ron Seifenberger <troja2977@my-deja.com> wrote:
> is there a possibility to join two hashes?
do an each or foreach over the first hash, copy elements
to new hash. Then each/foreach over second hash,
and add those elements to new hash as well.
Or you could try the code below.
Erik
#!/usr/local/bin/perl5.00404 -w
use strict;
my %hash1 = ( "A" => 65, "B" => 66 );
my %hash2 = ( "C" => 67, "D" => 68 );
my %hash = (%hash1, %hash2);
foreach (sort keys %hash) {
print "$_ $hash{$_}\n";
}
------------------------------
Date: 22 Oct 1999 20:13:11 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can I join two hashes?
Message-Id: <7uqggn$cms$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Erik van Roode
<newsposter@cthulhu.demon.nl>],
who wrote in article <7uqehp$9tr$1@internal-news.uu.net>:
> my %hash = (%hash1, %hash2);
One should also mention that this is not guarantied to be the same as
my %hash = (%hash2, %hash1);
Which is a feature.
Ilya
------------------------------
Date: Fri, 22 Oct 1999 12:18:12 -0700
From: Shuba Swaminathan <sswaminathan@micron.com>
Subject: Re: How to cut away decimals
Message-Id: <3810B874.65FA0FC0@micron.com>
int() is it.
Acacia wrote:
> I've checked the faq's, and could only find stuff about rounding the
> numbers...
> I need to cut away all decimals of any given number without rounding...
> for instance,
> 32.951251 --> 32
>
> does this have anything to do with int() ?
>
> any help will be greatly appreciated.
> acacia
------------------------------
Date: Fri, 22 Oct 1999 12:14:23 -0700
From: Shuba Swaminathan <sswaminathan@micron.com>
Subject: Re: How to round a number?
Message-Id: <3810B78F.78310F8D@micron.com>
Refer the FAQ at
http://language.perl.com/newdocs/pod/perlfaq4.html#Does_Perl_have_a_round_functio
Francois Dupradeau wrote:
> Dear All,
>
> Is there a function in Perl to round off the 2nd or the thrird (or the
> 5th, etc...) number after the decimal point of a number?
> ex:
> 3.123456789 => 3.123 (WITHOUT exponential)
>
> Thanks
> Regards
> Francois
>
> --
> Francois Dupradeau
> ------------
> Faculte de Pharmacie
> 1, rue des Louvels
> 80037 Amiens Cedex
> France
> ------------
> Tel 33 (0)3 22 82 74 94
> Fax 33 (0)3 22 82 74 69
> Email fyd@u-picardie.fr
------------------------------
Date: Fri, 22 Oct 1999 20:01:17 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: How to round a number?
Message-Id: <ho3Q3.26138$m4.94360054@news.magma.ca>
Tad McClellan <tadmc@metronet.com> wrote in:
news:h89pu7.291.ln@magna.metronet.com...
> Francois Dupradeau (fyd@u-picardie.fr) wrote:
>
> : Is there a function in Perl to round off
>
> Perl FAQ, part 4:
>
> "Does perl have a round function?
> What about ceil() and floor()?
> Trig functions?"
>
> You are expected to check the Perl FAQ *before* posting
> to the Perl newsgroup you know.
>
What is the recommendation if you need non-system-dependent rounding
behavior?
What if you can't tolerate the fact that on some systems (where "round
half to even" is implemented)
printf("%.0f", 0.5) prints 0
and on some other systems (where "round half up" is implemented)
printf("%.0f", 0.5) prints 1
Should i use something like the rounding functions in Math::BigFloat?
Or is something like the following good enough if i prefer "round half
up"?
sub round {
my $number = shift;
my $digits = shift;
my $mult = 10 ** $digits;
my $result;
if ($number >= 0) {
$result = int($number * $multiplicator + 0.5) / $mult;
} else {
$result = int(-$number * $multiplicator + 0.5) / -$mult;
}
return $result;
}
------------------------------
Date: Fri, 22 Oct 1999 20:23:37 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: How to round a number?
Message-Id: <dJ3Q3.26142$m4.94369177@news.magma.ca>
Tad McClellan <tadmc@metronet.com> wrote in:
news:h89pu7.291.ln@magna.metronet.com...
> Francois Dupradeau (fyd@u-picardie.fr) wrote:
>
> : Is there a function in Perl to round off
>
> Perl FAQ, part 4:
>
> "Does perl have a round function?
> What about ceil() and floor()?
> Trig functions?"
>
> You are expected to check the Perl FAQ *before* posting
> to the Perl newsgroup you know.
>
What is the recommendation if you need non-system-dependent rounding
behavior?
What if you can't tolerate the fact that on some systems (where "round
half to even" is implemented)
printf("%.0f", 0.5) prints 0
and on some other systems (where "round half up" is implemented)
printf("%.0f", 0.5) prints 1
Should i use something like the rounding functions in Math::BigFloat?
Or is something like the following good enough if i prefer "round half
up"?
sub round {
my $number = shift;
my $digits = shift;
my $mult = 10 ** $digits;
my $result;
if ($number >= 0) {
$result = int($number * $mult + 0.5) / $mult;
} else {
$result = int(-$number * $mult + 0.5) / -$mult;
}
return $result;
}
p.s. i just cancelled a version of my posting containing an obvious
error in the round function. If you see my posting twice, pls ignore
the previous version.
------------------------------
Date: 22 Oct 1999 15:38:30 -0400
From: James Peregrino <james_peregrino@harvard.edu>
Subject: Re: I'd like to know what are those CGIs and ASPs
Message-Id: <x7so33b2yx.fsf@bert.dce.harvard.edu>
Profisios <prophile@netvision.net.il> writes:
> I'd like to know what are those CGI and ASP scirpts and what languages it
> concerns.
First of all these *independent* of Perl.
A CGI is a program run on web server in a special environment. It
can be written in any language. Find the newsgroup on CGI programming for
more about this.
ASP is Active Server Pages, a technology developed by Microsoft for
Microsoft's web sever.
Go to Microsoft's web site for more on this.
-James
--
James Peregrino
Harvard Div. Continuing Education
------------------------------
Date: Fri, 22 Oct 1999 20:54:10 GMT
From: Scratchie <AgitatorsBand@yahoo.com>
Subject: Re: in need of example...
Message-Id: <S94Q3.1070$LR3.183437@news.shore.net>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
: No, the problem is when foo.jpg is a directory and you use ls *.jpg...
: you get the CONTENTS of foo.jpg.
OK, Randal... I agree that using a glob instead of `ls` is a better way to
do it, but you have to admit that this is an awfully contrived example.
Depending on the needs of the application in question, it might (and
probably would) be perfectly reasonable to assume that anything named
"*.jpg" is a JPEG image file.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Fri, 22 Oct 1999 13:44:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: mv file routine in perl for NT & Unix?
Message-Id: <Pine.GSO.4.10.9910221343130.29843-100000@user2.teleport.com>
On Thu, 21 Oct 1999, John Kit wrote:
> Is there a move file, mv, routine in perl which would
> work for NT & Unix?
See the File::Copy module's move function. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 22 Oct 1999 13:45:59 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Need for Speed - Perlcompiler?
Message-Id: <x3yhfjj8f1l.fsf@tigre.matrox.com>
"Bernd Kronmueller (EED)" <Bernd.Kronmueller@eedn.ericsson.se> writes:
> we are developing a quite big Perl application and now we slowly run
> into speed problems. Things take too long. Is there anything like a Perl
> compiler and has anybody experience with it?
Yes. Checkout perlfaq3:
How can I compile my Perl program into byte code or C?
Which has the following paragraph:
<QUOTE>
Merely compiling into C does not in and of itself guarantee that your
code will run very much faster. That's because except for lucky cases
where a lot of native type inferencing is possible, the normal Perl
run time system is still present and so your program will take just as
long to run and be just as big. Most programs save little more than
compilation time, leaving execution no more than 10-30% faster. A few
rare programs actually benefit significantly (like several times
faster), but this takes some tweaking of your code.
</QUOTE>
> We tried already several conventional ways to improve the code but it
> simply grows to large. So the possibility is a compiler or rewirting
> pieces in C. Is there any profiling function in Perl which gives the
> times a single subroutine takes so we can identify the important parts?
Definitely. You can use the Benchmark module, which is part of the
standard Perl distribution.
Also, I often resort to printing the current time after each
subroutine call in my programs. This gives me a rough estimation of
which parts take longer time, and then try to optimize them.
If you want to get the maximum speed with the maximum space
efficiency, then you should definitely go to C.
Perhaps if you identify the pieces of code where your program seems to
be taking the most amount of time, and then post them here, someone
will point you to a better way to do things.
HTH,
--Ala
------------------------------
Date: Fri, 22 Oct 1999 19:10:09 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: New short cut assignment operators?
Message-Id: <s11dkh435n676@corp.supernews.com>
Ala Qumsieh (aqumsieh@matrox.com) wrote:
: Those were invented for efficiency reasons.
:
: '$x += $y' is faster than '$x = $x + $y'.
Actually, this was invented in C to save typing and make intent clearer; a
good optimizer should generate identical code for the two. Hmmm...let's
see if Perl's optimizer is good:
#!/usr/bin/perl -w
# pluseq - benchmark two ways of adding to a variable.
# Craig Berry (19991022)
use strict;
use Benchmark;
my $a = 0;
timethese(shift || 10_000, {
'a += b' => '$a += 10',
'a = a + b' => '$a = $a + 10'
});
__END__
Results:
Benchmark: timing 500000 iterations of a += b, a = a + b...
a += b: 10 secs ( 5.71 usr 0.01 sys = 5.72 cpu)
a = a + b: 16 secs (10.74 usr 0.00 sys = 10.74 cpu)
Oops, guess Perl's expression optimizer isn't as good as most modern C
compilers'.
: > (Note: I often have the code like this, $a = $b . $a; so the shortcut maybe
: > useful in this situation. )
:
: You can use substr(), which should be faster (no benchmarks though).
Actually slower than . or "":
#!/usr/bin/perl -w
# prepend - benchmark ways to prepend text to a string
# Craig Berry (19991022)
use strict;
use Benchmark;
use vars qw($str $pre);
$str = 'hello world';
$pre = 'before ';
timethese(shift || 10_000, {
dot => '$_ = $str; $_ = $pre . $_;',
interp => '$_ = $str; $_ = "$pre$_";',
'substr' => '$_ = $str; substr($_, 0, 0) = $pre;',
NULL => '$_ = $str;'
});
__END__
Benchmark: timing 50000 iterations of NULL, dot, interp, substr...
NULL: 2 secs ( 1.06 usr 0.00 sys = 1.06 cpu)
dot: 5 secs ( 3.15 usr 0.00 sys = 3.15 cpu)
interp: 5 secs ( 3.34 usr 0.00 sys = 3.34 cpu)
substr: 7 secs ( 5.43 usr 0.00 sys = 5.43 cpu)
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "They do not preach that their God will rouse them
a little before the nuts work loose." - Kipling
------------------------------
Date: Fri, 22 Oct 1999 12:10:41 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: New short cut assignment operators?
Message-Id: <Pine.GSO.4.10.9910221208080.29843-100000@user2.teleport.com>
On Fri, 22 Oct 1999, Ala Qumsieh wrote:
> > And for $a = $b - $a; why not $a =- $b;
> Besides, there is a simple solution: $a += -$b
Did I cut too much? These are exact opposites. The first would be $b - $a,
while the second is $a - $b. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 22 Oct 1999 20:37:03 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: New short cut assignment operators?
Message-Id: <7uqhtf$dok$1@gellyfish.btinternet.com>
On 21 Oct 1999 21:02:03 GMT Email55555 wrote:
> The space (or newline) between operator and operant is important to avoid
> ambiguity,
> We already have this situation in Perl for operator x= .
> e.g.: $ax=4; is not the same as $a x=4;
>
No thats stupid - of course the white spice is important there as it
distinguishes two tokens - the variable $ax from a variable $a and an operator
. Perl unfortunately is cleverer than you are ....
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 22 Oct 1999 13:16:13 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: New short cut assignment operators?
Message-Id: <MPG.127a65e727c867c898a103@nntp.hpl.hp.com>
In article <s11dkh435n676@corp.supernews.com> on Fri, 22 Oct 1999
19:10:09 GMT, Craig Berry <cberry@cinenet.net> says...
> Ala Qumsieh (aqumsieh@matrox.com) wrote:
> : Those were invented for efficiency reasons.
> :
> : '$x += $y' is faster than '$x = $x + $y'.
>
> Actually, this was invented in C to save typing and make intent clearer;
Least important. More important is to avoid repeated lengthy
calculations:
a[i][j][k] = a[i][j][k] + x;
which should be compiled as:
char *p = &a[i][j][k];
*p = *p + x;
but probably isn't to this day, or (with possible side effects):
f() = f() + x;
> a good optimizer should generate identical code for the two.
Can it, even for 'simple' scalars? What about tied variables with side
effects?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 22 Oct 1999 13:28:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Newbie needs help with script! Should be easy for an expert.
Message-Id: <MPG.127a68bb28f8779b98a104@nntp.hpl.hp.com>
In article <01bf1cbd$1dc96dc0$54b2b28e@M26160> on 22 Oct 1999 18:41:43
GMT, CSRA <CSRA@tci.telus.com> says...
...
> Ran that script and I see what you are saying about the special rules.
> I had an overview of the problem but never got dirty with it before I
> started asking questions so didnt see what problems would arise.
General programming observation: The corner cases are what take the
most effort to get right. And if you don't test those cases, the users
inevitable will, and will let you know. Especially if the users are
people who see the code in this newsgroup. :-)
> www.perl.com
> Ever read the Purloined Letter? :)
Yes. Hidden right under your nose.
> Thanks for the help!
Even though I didn't send you e-mail? You're welcome.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 22 Oct 1999 19:22:25 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Perl and shadow passwords
Message-Id: <RP2Q3.28845$E_1.1571392@typ11.nn.bcandid.com>
In article <Pine.GSO.4.10.9910221200180.29843-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
>You do know about the MD5 module, right? But if you need to know how
>Linux's shadow file works, check the manpages and Linux newsgroups. Good
And info. The glibc info explains the format of the MD5 password storage and
how to get crypt() to do MD5.
zcat /usr/info/libc.*|less
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Fri, 22 Oct 1999 10:35:09 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Exam Beta Testers Required - How good are you?
Message-Id: <tmspu7.ru1.ln@magna.metronet.com>
Munish Suri (msuri@recruitsource.com) wrote:
^^^^^^^
: My company is working on an online technical screening system that is
: to-be-shortly released. We are looking for experienced individuals to test
^^^^^^^^^^^
: our Perl exams.
: Please respond ASAP if you are interested.
Please post what you are planing to pay if you want to
generate interest.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 22 Oct 1999 21:24:13 +0100
From: "Aerial" <aerial@online.no>
Subject: Please help!
Message-Id: <nP2Q3.9272$7G2.53426@news1.online.no>
I've made a download manager calculating download times at various speeds.
However, when using
$hours:$minutes:$seconds, I sometimes get outputs like 0:24:5
It doesn't look very nice at all, so I'm wondering if there is a way of
making it turn out like 00:24:05 ...
Thanks
------------------------------
Date: Fri, 22 Oct 1999 19:24:34 GMT
From: Marcel Grunauer <marcel.grunauer@lovely.net>
Subject: Re: Please help!
Message-Id: <sccQOJjws=F0qev7doLqVD40lNu=@4ax.com>
On Fri, 22 Oct 1999 21:24:13 +0100, "Aerial" <aerial@online.no> wrote:
> I've made a download manager calculating download times at various speeds.
> However, when using
> $hours:$minutes:$seconds, I sometimes get outputs like 0:24:5
> It doesn't look very nice at all, so I'm wondering if there is a way of
> making it turn out like 00:24:05 ...
perldoc -f printf
perldoc -f sprintf
--
Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;
------------------------------
Date: Fri, 22 Oct 1999 19:32:21 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Please help!
Message-Id: <9Z2Q3.28880$E_1.1572113@typ11.nn.bcandid.com>
In article <nP2Q3.9272$7G2.53426@news1.online.no>,
Aerial <aerial@online.no> wrote:
>I've made a download manager calculating download times at various speeds.
>However, when using
>$hours:$minutes:$seconds, I sometimes get outputs like 0:24:5
>It doesn't look very nice at all, so I'm wondering if there is a way of
>making it turn out like 00:24:05 ...
$t = sprintf("%02d:%02d:%02d", $h, $m, $s);
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: Fri, 22 Oct 1999 12:07:22 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: PostgreSQL interfaces
Message-Id: <mbudash-2210991207220001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <3810b22c.55382008@nntp.ix.netcom.com>, quikscor@ix.netcom.com
(Jana Cole or John Sayre) wrote:
>My ISP allows me access to PostgreSQL. I am new to Perl.
>
>At the CPAN site I see two ways to interface with PostgreSQL: a Pg
>module that "permits you to access all functions of the Libpq
>interface of PostgreSQL" and I see DBD::Pg which "works with the DBI
>module to provide access to PostgreSQL databases."
>
>Is one of these "better" than the other? Are there any major
>differences in functionality or ease of use?
>
>I'm going to be doing super-simple database searches like
>city AND country AND price_range
>I don't anticipate anything more comlicated than this type of thing.
>
>-j
my recommendation:
use DBI;
it just makes sense to use an interface that uses one set of syntax
[nearly] regardless of which dbms it's accessing, and it can access (via
the DBD's of course) lots of 'em!
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Fri, 22 Oct 1999 13:48:36 -0700
From: Hal Mounce <hal_mounce@amdahl.com>
Subject: seeking past 4GB
Message-Id: <3810CDA4.BDF30CFE@amdahl.com>
I wrote a script to mark a file with eyecatchers like S6LBA0000F40+1E0
so that I could catch read and write activity with a channel sniffer,
and catch overlays and stuff.
I seem to be able to write all day long to a disk using print. When I
go to read a specific block however, I get tripped up past 4GB (32 bits
worth of byte offset).
I notice also that some of my variables get weird once they hit 4G.
Here's some code:
#!/opt/perl5/bin/perl -w
$source_file = $ARGV[0];
chomp $source_file;
# collect filesize information
$devinfo = `/usr/sbin/devinfo -i $source_file`;
die "$0: can't determine blocksize for $source_file: $?\n" unless $? ==
0;
$block_size = (split /\s+/, $devinfo)[4];
chomp($block_size);
$devinfo = `/usr/sbin/devinfo -p $source_file`;
die "$0: can't determine number of blocks in $source_file: $?\n" unless
$? == 0;
$num_blocks = (split /\s+/, $devinfo)[4];
chomp($num_blocks);
$filesize = $block_size * $num_blocks;
$fmeg = $filesize / (1024 * 1024);
$fgig = $filesize / ((1024 * 1024) * 1024);
print "-->$num_blocks<-- num_blocks\n";
print "-->$block_size<-- block_size\n";
print "-->$filesize<-- filesize\n";
print "-->$fmeg<-- fmeg\n";
print "-->$fgig<-- fgb\n";
printf "File size is %16ld or %16.16lX bytes\n", $filesize, $filesize;
printf "File size is %16.3f or %16.16lX Mbytes\n", $fmeg, $fmeg;
printf "File size is %16.3f or %16.16lX Gbytes\n", $fgig, $fgig;
print "\n";
# seek to different spots and read what's there
open(SRC, "< $source_file") or die "$0: can't open $source_file for
reading: $!\n";
$last = $filesize -16; #last eyecatcher in the file
$onemeg = 1024 * 1024;
$onegig = $onemeg * 1024;
$twogig = $onegig * 2;
$notquite4gig = ($onegig * 4) - 512; # one LBA short of 4GB
$fourgig = $onegig * 4;
$fourgig1 = $fourgig + 512;
$unlucky = ($onegig * 13) + ($onemeg * 13) + (512 * 13);
$last = $filesize - 512; #first eyecatcher in last lba of the file
foreach $offset (0, 512, $onemeg, $twogig, $notquite4gig, $fourgig,
$fourgig1, $unlucky, $last) {
seek(SRC, $offset, 0) or die "$0: can't seek to offset $offset:
$!\n";
read(SRC, $buffer, 16) or die "$0: read failed at offset $offset:
$!\n";
print "offset -->$offset<-- buffer -->$buffer<--\n";
printf "hex offset %16.16lX buffer %s\n", $offset, $buffer;
$lba = substr($buffer, 5, 7); # x from SnLBAxxxxxxx+yyy
$byte = substr($buffer, 13, 3); # y from SnLBAxxxxxxx+yyy
$binlba = hex $lba;
$binbyte = hex $byte;
$as_read_offset = ($binlba * 512) + $binbyte;
print "offset -->$offset<-- survey says -->$as_read_offset<--\n\n";
}
close SRC or die"$0: can't close $source_file: $!\n";
__END__
Here's some output:
# ./bigfile
/dev/rdsk/c2t4d41s6
-->28174620<-- num_blocks
-->512<-- block_size
-->14425405440<-- filesize
-->13757.138671875<-- fmeg
-->13.4347057342529<-- fgb
File size is -1 or 00000000FFFFFFFF bytes
File size is 13757.139 or 00000000000035BD Mbytes
File size is 13.435 or 000000000000000D Gbytes
offset -->0<-- buffer -->S6LBA0000000+000<--
hex offset 0000000000000000 buffer S6LBA0000000+000
offset -->0<-- survey says -->0<--
offset -->512<-- buffer -->S6LBA0000001+000<--
hex offset 0000000000000200 buffer S6LBA0000001+000
offset -->512<-- survey says -->512<--
offset -->1048576<-- buffer -->S6LBA0000800+000<--
hex offset 0000000000100000 buffer S6LBA0000800+000
offset -->1048576<-- survey says -->1048576<--
offset -->2147483648<-- buffer -->S6LBA0400000+000<--
hex offset 0000000080000000 buffer S6LBA0400000+000
offset -->2147483648<-- survey says -->2147483648<--
offset -->4294966784<-- buffer -->S6LBA07FFFFF+000<--
hex offset 00000000FFFFFE00 buffer S6LBA07FFFFF+000
offset -->4294966784<-- survey says -->4294966784<--
./bigfile: can't seek to offset 4294967296:
I'd like to be able to seek way on out there, and I'm not so thrilled
with
File size is -1 or 00000000FFFFFFFF bytes
either.
Oh, yeah...
# perl -v
This is perl, version 5.005_03 built for sun4-solaris
Any clues would be appreciated.
--Hal
------------------------------
Date: Fri, 22 Oct 1999 16:29:08 -0400
From: "TechGuy" <michael@cermak.com>
Subject: Re: stealing the news: how hard can it be?
Message-Id: <lO3Q3.3956$l05.76513@typ11a.deja.bcandid.com>
Is there any chance you could send me a bit of this script or point me to a
resource where I could learn to do something similar?
Thanks,
-Mike
dsparling wrote in message <7uo0ai$lvj$1@nnrp1.deja.com>...
>I'm curious of the legal ramifications if I want to do this on a
>commercial site...I've written a Perl CGI script to pull weather info
>from rainorshine.com that I'd like to use on one of my projects.
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
------------------------------
Date: Fri, 22 Oct 1999 11:23:56 -0700
From: Shuba Swaminathan <sswaminathan@micron.com>
Subject: Re: Unlink
Message-Id: <3810ABBC.A08ADD40@micron.com>
>
>
> There is no concatanation operator there. If $num = '001' then
> you will be trying to delete the file : 'LOCK.001'. If you want to
> delete 'LOCK001' then remove the . from the string...
I apologize, that was a mistake. I copy pasted the test code by accident,
where I tried to get rid of the concatenation operator thinking that may be
the problem. But this change didn't help either.
My original code read "lock.".$num. The file that I am trying to delete is
lock.001. Is one of these better than the other in terms of style and
efficiency?
>
> Why don't you ask perl what the problem is....
>
> unlink("LOCK.$num") or die "022 Could not delete lock file $!";
>
> Feel free to change the die into your convoluted eval mess if you like ;)
I did ask Perl and it reports no problems which is why I am at my wits to
explain the sporadic failures!
The reason I have that eval mess is because I didn't know how else to return
error levels to my DOS Batch file. Let me expand - I am converting this perl
script into an exe and calling that from a batch file. (Perl cannot be
installed on that system for a lot of reasons and hence the need to make an
exe out of it). If this script returns an error level 0, I need it to execute
perl script A.If the error level returned is 1, I need it to execute script B
and if the level is 2, I need it to execute script C. I didn't know how to do
this more elegantly and efficiently. Any pointers to better programming would
be gratefully recieved.
Thanks,
Shuba.
------------------------------
Date: Fri, 22 Oct 1999 13:52:16 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Unlink
Message-Id: <Pine.GSO.4.10.9910221347540.29843-100000@user2.teleport.com>
On Thu, 21 Oct 1999, Shuba Swaminathan wrote:
> Have you had any experience with "unlink" being
> unreliable?
Nope.
> unlink("LOCK.$num") or eval {print ERROR "022
> Could not delete lock file\n"; exit 1;};;
Why are you using eval? You should rewrite this as an 'if' or 'unless', if
that's what you want.
unless (unlink "LOCK.$num") {
print ERROR "022 Couldn't delete lock file 'LOCK.$num': $!\n";
exit 1;
}
> I want it to delete files with names like lock.001, lock.002 etc.
Then you shouldn't be trying to delete files with names like 'LOCK.1',
should you? :-)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 22 Oct 1999 19:35:26 GMT
From: intbyte@aol.com (Max S.)
Subject: URGENT: Adding a AUTO-Email to Matt Writtes FFA Links
Message-Id: <19991022153526.23686.00000023@ng-cg1.aol.com>
i am new to perl, very new, and i was wondering if someone could email me a
code to add to matt writte ffa links script to have it e-mail ME each time
someone adds a link, check out my web page and see what I have
PLEASE E-Mail me because I don't check here too often (intbyte@aol.com)
Max S.
intbyte@aol.com
http://realestateclosings.net/zd
------------------------------
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 V9 Issue 1154
**************************************