[13880] in Perl-Users-Digest
Perl-Users Digest, Issue: 1290 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 5 06:05:32 1999
Date: Fri, 5 Nov 1999 03:05:11 -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: <941799911-v9-i1290@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 5 Nov 1999 Volume: 9 Number: 1290
Today's topics:
Re: evaluating a string (Craig Berry)
Re: FAQ 7.12: What's a closure? <skilchen@swissonline.ch>
Re: flock <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
How can I determine different "use" statements? <mozo@wahoo.com.tw>
Re: how sort an array? (Neko)
Re: how sort an array? (Abigail)
Re: how sort an array? (Anno Siegel)
Re: how sort an array? (Anno Siegel)
Re: mod_perl installation problem <aboudeif@pixelpark.com>
Re: password question ardit@my-deja.com
Re: perl on windows NT <carvdawg@patriot.net>
Re: Round off a number <skilchen@swissonline.ch>
SQL 6.5 and Apache <any@any.com>
Why doesn't thhis work? <kimf@post.tele.dk>
Re: Why doesn't thhis work? <slanning@bu.edu>
Re: Why doesn't thhis work? <flavell@a5.ph.gla.ac.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Nov 1999 08:07:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: evaluating a string
Message-Id: <s2541970hpc16@corp.supernews.com>
Steve Dries (sdries3@home.com) wrote:
: I have a string that is a known format but will have a different number in
: it..here's an example:
:
: The number you're trying to get is 347373 so good luck.
:
: All I'm trying to do is get that number out of the string into it's own
: variable. Again, please forgive this seemingly easy question and I apologize
: if it's in a FAQ somewhere that I haven't found. Thanks.
Study up on regexes (perldoc perlre). If your requirement can be restated
as "Find the first sequence of digits in a string and put that sequence
into a scalar", then this will suffice:
my ($num) = $str =~ m/(\d+)/;
--
| 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, 05 Nov 1999 09:59:13 GMT
From: Samuel Kilchenmann <skilchen@swissonline.ch>
Subject: Re: FAQ 7.12: What's a closure?
Message-Id: <7vu9pg$c15$1@nnrp1.deja.com>
Tom Christiansen <perlfaq-suggestions@perl.com> wrote in message
news:382145d1@cs.colorado.edu...
> (This excerpt from perlfaq7 - Perl Language Issues
>
> Here's a classic function-generating function:
>
> sub add_function_generator {
> return sub { shift + shift };
> }
>
I always found that example a little bit strange in a FAQ about
closures. Isn't that a "pathological" case of a closure which
doesn't "close" anything?
Does somebody know an answer to the question raised by Kragen Sitaker
(in news:20OT3.23363$23.1206512@typ11.nn.bcandid.com: "I don't know what
the heck is going on with sub1"). Unfortunately this question is not
asked frequently enough to get an answer in the FAQ.
(I assume that the "closure" below does the same thing as
Kragen's "sub1". Sorry in advance if i - once more - missed
an evident explanation.)
IMHO the following two code snippets are mostly equivalent. The
first written in Perl the second in Scheme. What is the reason for the
difference in their behavior?
The Perl version prints:
within scope: 1
outside scope: Use of uninitialized value at <scriptname> line 21.
The Scheme version prints:
within scope: 4321
outside scope: 4321
The Perl version:
#!wherever/perl -w
use strict;
use vars qw($value);
$value = 4321;
sub test {
my $closure;
my $value = 1;
$closure = sub { eval '$value'; };
print "within scope: ";
print $closure->();
print "\n";
$value = 2;
$closure;
}
sub dotest {
my $closure = test();
print "outside scope: ";
print $closure->(); # this is line 21
print "\n";
}
dotest();
The Scheme version:
(define value 4321)
(define (test)
(let* ((value 1)
(closure (lambda ()
(eval 'value))))
(display "within scope: ")
(display (closure))
(newline)
(set! value 2)
closure))
(define (dotest)
(let ((closure (test)))
(display "outside scope: ")
(display (closure))
(newline)))
(dotest)
If i change the snippets as follows
Perl:
$closure = sub { eval $variable; };
and Scheme:
(closure (lambda ()
(eval value)))
then both versions print:
within scope: 1
outside scope: 2
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 05 Nov 1999 01:32:57 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: flock
Message-Id: <11f733ec.b3f42fb0@usw-ex0101-004.remarq.com>
In article <382241e5.67722414@news.acronet.net>, nihilist@kenobiz.com
(Max) wrote:
> if i flock(YESFILE, 2) what happens when another file requests
> that
> same file? does it just die, or does it get placed in a queue?
Probably the same thing that happened for the person that asked this
question the day before yesterday...
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 05 Nov 1999 18:19:29 +0800
From: mozo <mozo@wahoo.com.tw>
Subject: How can I determine different "use" statements?
Message-Id: <3822AF31.411D0C94@wahoo.com.tw>
Since the use statements are run on compile-time,
How can I determine which module to be used in program?
I do it this way:
if(condition){
use module1;
use module2;
}else{
use module3;
use moudle4;
}
...
...
But It seem need to have all 4 modules availble all the time,
no matter what the condition is.
What can I do?
--
胡崇賢 網虎國際 http://wahoo.com.tw
mailto:mozo@wahoo.com.tw
------------------------------
Date: Fri, 05 Nov 1999 00:05:50 -0800
From: tgy@chocobo.org (Neko)
Subject: Re: how sort an array?
Message-Id: <TYsiONezCnr9pFg9dPbKGe+LN444@4ax.com>
On Fri, 05 Nov 1999 06:18:54 GMT, andrew-johnson@home.com (Andrew Johnson)
wrote:
>In article <x7bt997bus.fsf@home.sysarch.com>,
> Uri Guttman <uri@sysarch.com> wrote:
>! >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>[snip]
>! LR> ULP!
>!
>! Uri's and Larry's Pack?
>!
>! this is going downhill very fast without brakes.
>
>something like the 'ROGUE' pack sort sounds rather cool and
>mysterious --- with a few alternatives for the E:
>
>ROsler GUttman Efficient pack sort
> Effective
> Elusive
> Egregious
> Economic
> Emancipated
> Eminent
> Elderberry
Empty
...that is, sort with an Empty or default comparison block. But if it needs
explaining, then maybe Elderberry would work better. :)
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: 5 Nov 1999 03:56:47 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: how sort an array?
Message-Id: <slrn825alv.dk.abigail@alexandra.delanet.com>
Ilya Zakharevich (ilya@math.ohio-state.edu) wrote on MMCCLVII September
MCMXCIII in <URL:news:7vu1t1$sbb$1@charm.magnus.acs.ohio-state.edu>:
:: [A complimentary Cc of this posting was sent to Abigail
:: <abigail@delanet.com>],
:: who wrote in article <slrn82511g.dk.abigail@alexandra.delanet.com>:
:: > The "simplicity" of ST lies in the fact that given the sort function,
:: > the creation of the ST is mechanical. And it works all the time.
::
:: If it is true, then it is the compiler who should do it, not the
:: coder.
It would be nice if the compiler did. Unfortunally, I don't have the
patience to get enough tuits to do it myself.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 5 Nov 1999 09:58:55 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how sort an array?
Message-Id: <7vu9ov$f2v$1@lublin.zrz.tu-berlin.de>
Larry Rosler <lr@hpl.hp.com> wrote in comp.lang.perl.misc:
[snip]
>#!/usr/local/bin/perl -w
>use strict;
>
>my $file = 'ips.txt';
>
>sub external {
> my @start = times;
> my @array = `sort $file`;
> my @end = times;
> print map { my $t = $end[$_] - $start[$_]; "$t\n"} 0 .. 3;
>}
>
>sub internal {
> my @start = times;
> open IN, $file or die "Couldn't open '$file'. $!\n";
> my @array = sort <IN>;
> my @end = times;
> print map { my $t = $end[$_] - $start[$_]; "$t\n"} 0 .. 3;
>}
>
>external();
>print "\n";
>internal();
>__END__
>
>Output (2 runs on single-user HP-UX 9.05, perl 5.005_03):
>
>2.04 1.93
>0.29 0.45
>10.33 10.07
>0.6 0.57
>
>6.7 6.61
>0.3 0.27
>0 0
>0 0
>
>Interpretation:
>
>The input file is 100000 lines of about 35 characters/line (the same
>file as used in the benchmarks for the sorting paper).
>
>The internal sort seems to run about twice as fast, for this one test.
>
>Any other experiments would be welcome.
A single run under Linux on a 90 MHz Pentium (don't look at me, it's
quite adequate) gives me this
5.34
1.61
3.92
1.43
11.58
0.91
0
0
So there's no significant difference between perl's sort and the
sort command. Interesting, though I don't claim to have an idea
why this would happen. Both runs seem to grab the roughly 16 MB
of currently available memory (no surprise there).
I failed to find the ips.txt you used starting from your home page,
so I rolled my own (100000 lines of exactly 35 random characters).
I'd like to do a re-run with the original data, though a big
difference in performance would be a surprise.
Anno
------------------------------
Date: 5 Nov 1999 10:09:28 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how sort an array?
Message-Id: <7vuaco$f55$1@lublin.zrz.tu-berlin.de>
David Cassell <cassell@mail.cor.epa.gov> wrote in comp.lang.perl.misc:
>Mark Bluemel wrote:
>>
>> In article <7vs455$ogn$1@nnrp1.deja.com>, skeeta@gmx.net wrote:
>> > Hello,
>> > I have a problem with sorting an array.
>> > I have a file, in which all the data is stored like this:
>[snip]
>> Don't do it in Perl - use your operating system's "sort" command...
>
>Umm, since he sent this from a WinNT box, are you sure that's
>a good idea?
>
>Besides, if you want to look like a Perl guru, you have to use
>the latest, most obscure technique: GRP, the Guttman-Rosler
>Packsort. Pronounce it 'gripe' or 'group' or 'grope' or
>'grape' or 'garp' depending on your feelings about it...
Garp! That should settle the name conflict.
Anno
PS: Does it wrestle? Have a nurse for a mother? Was it spawned
in hospital by an only partially disabled.... No, this is a
family newsgroup.
------------------------------
Date: Fri, 05 Nov 1999 11:21:19 +0100
From: ottmar deifke netsc ape <aboudeif@pixelpark.com>
Subject: Re: mod_perl installation problem
Message-Id: <3822AF9F.D50E858D@pixelpark.com>
hi kragen,
thanks for your help. this is the ldd output:
Kragen Sitaker wrote:
> What do you get if you ldd gen_test_char on machine 1? Does it mention
> libperl.so? If so, where is it getting it?
>
> I'm pretty mystified by this, too. I looked at your compile output,
> and it looks like it's not finding libperl.so immediately after it
> (presumably) found it during the compile.
>
ldd reports:
(gmake clean, configure, make->ok)
machine 1:
ldd /park/pub/source/www/apache/apache/src/main/gen_test_char
libgdbm.so => /www/lib/libgdbm.so
libsocket.so.1 => /usr/lib/libsocket.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
(gmake clean, configure, make->error)
machine 2:
ldd /park/pub/source/www/apache/apache/src/main/gen_test_char
libgdbm.so => /www/lib/libgdbm.so
libsocket.so.1 => /usr/lib/libsocket.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libperl.so => (file not found)
libdl.so.1 => /usr/lib/libdl.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libcrypt_i.so.1 => /usr/lib/libcrypt_i.so.1
libmp.so.2 => /usr/lib/libmp.so.2
libgen.so.1 => /usr/lib/libgen.so.1
so how come that gen_test_char suddenly needs libperl.so?
again, its the same source, only the perltree is installed twice.
> I'm pretty mystified by this, too.
aah. this makes me feel better.
--
regards,
()mar /\bou |)eif
------------------------------
Date: Fri, 05 Nov 1999 08:51:24 GMT
From: ardit@my-deja.com
Subject: Re: password question
Message-Id: <7vu5qc$9lh$1@nnrp1.deja.com>
In article <Pine.GSO.4.10.9911041709450.29670-
100000@user2.teleport.com>,
Tom Phoenix <rootbeer@redcat.com> wrote:
> On Fri, 5 Nov 1999 ardit@my-deja.com wrote:
>
> > I have a perl script that gets news from the internet, one of the
> > websites I'm trying to access is password protected, the problem is
> > that I don't know how to put the password and the username in my
perl
> > script in order to retrieve news from that site, I get news with
out a
> > problem from other sites that are not protected by a password. Is
there
> > any code I should use in the script?
>
> Yes.
>
> If you're using a module, see its docs to discover how to pass a
username
> and password. If you're not using a module, get one from CPAN and see
its
> docs.
>
> Also, please consider using the punctuation mark period (".") when you
> reach the end of a declarative sentence, since that makes your text
easier
> to read.
>
> Cheers!
>
> --
I'm using LWP::Simple
here is part of the script:
#!/usr/bin/perl
use LWP::Simple;
print "pragma:no-cache\n";
print "content-type:text/html\n\n";
$url = 'http://interactive.com';
$doc = get($url) or do {
print "Can't get News";
exit (0);
};
ardit
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 05 Nov 1999 05:47:42 -0500
From: "Harlan Carvey, CISSP" <carvdawg@patriot.net>
Subject: Re: perl on windows NT
Message-Id: <3822B5CE.A7F2B6FD@patriot.net>
> I want to be able to find out from a perl code if a process with gived
> pid exists on the local Windows NT machine.
Win32::Process, or Win32::iProc will work.
------------------------------
Date: Fri, 05 Nov 1999 09:45:34 GMT
From: Samuel Kilchenmann <skilchen@swissonline.ch>
Subject: Re: Round off a number
Message-Id: <7vu8vt$bks$1@nnrp1.deja.com>
In article <3822166C.A01E6C09@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> wrote:
> Frank de Bot wrote:
> [snip]
> > $round1 = int($string * 1 +0.5) / 1; # 1
> > $round2 = int($string * 10 + 0.5) / 10; # 1.23
> > $round3 = int($string * 100 + 0.5) / 100; # 1.235
> > $round4 = int($string * 1000 +0.5) / 1000; # 1.246
> > $round5 = int($string * 10000 + 0.5) / 10000; # 1.2346
> > $round6 = int($string * 100000 + 0.5) / 100000; # 1.23457
> >
> > And so on. You can see it rounds up and down. ( Next decimal = 5
> > rounds up. Else down)
>
> Frank:
> [1] Please use the preferred answers in the FAQ to your own
> homegrown versions.
No! Don't round numbers with (s)printf unless you know what you are
doing. (The rounding behavior of sprintf is system dependent and the
behavior on *nixish systems is "round half to even", which is not what
most people expect.
> [2] This does not appear to be IEEE-compliant - did you check?
Come on! Why should a Perl programmer care about IEEE-compliancy? Thats
rather evidently Perl's duty (does Perl care about IEEE-compliancy?).
Btw. what Frank posted, corresponds roughly to what IEEE calls "round
to positive infinity".
I repeat my request that one of the Perl gurus should add an idiomatic
version of a round function to perlfaq4 which should do what most
people expect and what is described in many places (although it doesn't
describe the rounding behavior of sprintf): round half away from zero.
(And i still think that such a function should be available as a Perl
builtin.)
My current favorite:
sub round_to_digits {
my $number = shift;
my $digits = shift;
my $multiple = 10 ** -$digits;
return round_to_multiple($number, $multiple);
}
sub round_to_multiple {
my $number = shift;
my $multiple = shift;
my $result;
if ($number > 0) {
$result = int($number / $multiple + 0.5) * $multiple;
} elsif ($number < 0) {
$result = int($number / $multiple - 0.5) * $multiple;
} else {
$result = 0;
}
return $result;
}
That handles both the cases where you want to round to a fixed number
of decimals and the case where you want to round to a multiple of a
value, e.g. 0.05. But it doesn't help in the area of the mysteries of
floating point arithmetic. If you don't like that numbers like 16.185
will be rounded down to 16.18 then you have to use something like
Math::BigFloat.
use strict;
use Math::BigFloat;
sub round_big_float {
my $number = shift;
my $digits = shift;
if ($number lt "0") {
$Math::BigFloat::rnd_mode = "-inf";
} else {
$Math::BigFloat::rnd_mode = "+inf";
}
my $result = Math::BigFloat::ffround($number, -$digits);
$result = Math::BigFloat->new($result);
return $result;
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 5 Nov 1999 17:57:20 +0800
From: "一月" <any@any.com>
Subject: SQL 6.5 and Apache
Message-Id: <7vu9bp$ff2$1@news.hk.linkage.net>
Machine 1 - Linux, Apache Web Server, Openlink Driver, Perl 5.05.
Machine 2 - NT, MSSQL 6.5, ODBC, Openlink Server
DB details: dbname=test, user=sa, passwd =, DSN=Test SQL
If I use perl to connect two machine(machine get data from machine 2), how
should I config the DSN??
ie.$dbh=DBI->connect($DSN, $user, $passwd)
what is this $DSN??
DBI:ODBC:??? or sth else??
------------------------------
Date: Fri, 05 Nov 1999 09:31:48 +0100
From: Kim Frederiksen <kimf@post.tele.dk>
Subject: Why doesn't thhis work?
Message-Id: <382295F4.F571FF70@post.tele.dk>
Hope someone can help me, this doesn't work, and I don't know why. It's
supposed to detect the country from the remote_host:
@ALLOW_HOSTS = ('.dk', '.se', '.no');
$rhost="";
$rhost=$ENV{'REMOTE_HOST'};
foreach $host (@ALLOW_HOSTS)
{
if ( $rhost =~ /$host$/)
{
tam tam tam;
last;
}
}
Thanks in advance,
--
Best Regards,
Kim Frederiksen
mailto:kimf@post.tele.dk
ICQ Nr: 5033313
----------------------------------------------
------------------------------
Date: 05 Nov 1999 04:53:03 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: Why doesn't thhis work?
Message-Id: <kusg0yl1czk.fsf@bottom.bu.edu>
Kim Frederiksen <kimf@post.tele.dk> writes:
> Hope someone can help me, this doesn't work, and I don't know
> why. It's supposed to detect the country from the remote_host:
Umm, that's like a CGI question by the way.
goto comp.infosystems.www.authoring.cgi
Why didn't you post the entire script? When I filled in
the blanks, it worked for me...........
> @ALLOW_HOSTS = ('.dk', '.se', '.no');
>
> $rhost="";
> $rhost=$ENV{'REMOTE_HOST'};
>
> foreach $host (@ALLOW_HOSTS)
> {
> if ( $rhost =~ /$host$/)
[snip]
--
"If lightning is the anger of the gods, the gods are concerned mostly
with trees." --Lao Tse
------------------------------
Date: Fri, 5 Nov 1999 10:44:20 +0000
From: "Alan J. Flavell" <flavell@a5.ph.gla.ac.uk>
Subject: Re: Why doesn't thhis work?
Message-Id: <Pine.OSF.4.20.9911051042040.15235-100000@a5.ph.gla.ac.uk>
On 5 Nov 1999, Scott Lanning wrote:
> Umm, that's like a CGI question by the way.
> goto comp.infosystems.www.authoring.cgi
Quite
> Why didn't you post the entire script?
Wouldn't have helped. Apart from the fact that the idea is
misconceived, it's a server configuration issue.
> When I filled in
> the blanks, it worked for me...........
REMOTE_HOST will only be filled in if the server looked it up.
But this is the wrong place to look for such answers, and, as I
say, the idea is misconceived, for various different reasons.
------------------------------
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 1290
**************************************