[19441] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1636 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 28 09:05:31 2001

Date: Tue, 28 Aug 2001 06: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: <999003910-v10-i1636@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 28 Aug 2001     Volume: 10 Number: 1636

Today's topics:
    Re: A bit of expaination of caller() please (Anno Siegel)
        Adding a html break tag at eol in text... <mlaw@talk21.comNOSPAM>
    Re: adding rows in a text file (soumitra bhattacharya)
    Re: adding rows in a text file (Anno Siegel)
    Re: Avoiding symbolic references. <joe+usenet@sunstarsys.com>
    Re: Avoiding symbolic references. (Anno Siegel)
        Checking entries in a CSV file....? (Pete Sohi)
    Re: Checking entries in a CSV file....? <rsherman@ce.gatech.edu>
    Re: CODE reference to member function of package Confus (Anno Siegel)
        DBI connect string for Sybase Anywhere Studio <kkoch@kxsu.de>
        DBI Question <markus.linke@ib.bankgesellschaft.de>
    Re: how to get named constants in Perl (Randal L. Schwartz)
    Re: how to get named constants in Perl <bart.lateur@skynet.be>
    Re: how to get named constants in Perl (Peter J. Acklam)
    Re: how to get named constants in Perl (Bernard El-Hagin)
    Re: how to get named constants in Perl (Peter J. Acklam)
    Re: how to get named constants in Perl (Bernard El-Hagin)
    Re: how to get named constants in Perl (Peter J. Acklam)
    Re: how to get named constants in Perl (Anno Siegel)
    Re: Java mucks up split <bcaligari@fireforged.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 28 Aug 2001 11:34:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A bit of expaination of caller() please
Message-Id: <9mfvkt$jl1$2@mamenchi.zrz.TU-Berlin.DE>

According to Stan Brown <stanb@panix.com>:
> How can I use caller() to print out the current callstack? All of it thta
> is?

    my $i = 0;
    while ( @context = caller( $i++) {
        print "$i: @context\n";
    }

Anno
-- 
use overload '${}' => sub { \ 'Just '}, '@{}' => sub { [ 'another ']},
'%{}' => sub { { a => 'Perl '}}, '&{}' => sub { sub { print @_, 'hacker'}};
$plop = bless [];
$plop->( $$plop, $plop->[ 0], $plop->{ a});


------------------------------

Date: Tue, 28 Aug 2001 11:56:41 +0100
From: "Matt L." <mlaw@talk21.comNOSPAM>
Subject: Adding a html break tag at eol in text...
Message-Id: <9mftda$74b$1@newsreaderg1.core.theplanet.net>

Hi,

I appreciate that this maybe a tall order to ask for help, so many thanks
for any replies:

I have a textarea on a web page that allows the user to edit their own web
site news page. I am submitting this page to a CGI.  I need a snippet of
code (or some guidance 80) that reads in the text from the aforementioned
textarea and inserts a html <br> tag wherever the end of line character is
encountered.

Since the users are not able to code their own html I am making the
assumption that wherever they have pressed the enter key they would like an
html line break inserted in the text so that it appears in the browser as it
did in the textarea.

Does it make any difference that the CGI runs on Linux and the textarea is
edited on a Win32 based system?

Many thanks in advance,

Matthew.




------------------------------

Date: 28 Aug 2001 03:50:36 -0700
From: soumitra@mailandnews.com (soumitra bhattacharya)
Subject: Re: adding rows in a text file
Message-Id: <72fd0cf4.0108280250.6ee0d10b@posting.google.com>

Thank you very much John.
I have figured out the modification needed too....

while (<ZZZ>)
{
    next if /^#/;# discard comments
    my ($index,@data) = split(/\|\|/,$_); # or whatever
    my $key;
    for ($index)
    { $_ < 5  && do { $key = $_; last; };
        $_ < 11 && do { $key = "5-10"; last; };
        $_ < 21 && do { $key = "11-20"; last; };
        $_ < 31 && do { $key = "21-30"; last; };
        $_ < 41 && do { $key = "31-40"; last; };
        $_ < 51 && do { $key = "41-50"; last; };
        $key = "50+";
    }for (my $i=0;$i <= $#data;$i++){
        $sum{$key}{$i} += $data[$i];
        $sum{$key}{'count'} ||=0;
        $sum{$key}{'count'} ++;

  }foreach my $key (keys %sum){
    print "<HR>key is $key <BR>";
     $cnt =($sum{$key}{'count'}/5);
    print "cnt is $cnt<BR>";
    foreach my $data (keys %{$sum{$key}}) {
        next if $data eq 'count';
        $tmp = int((($sum{$key}{$data})/($cnt)));
        print "$data => $sum{$key}{$data} and tmp is $tmp<BR>";}
 }
}
trammell@haqq.hypersloth.invalid (John J. Trammell) wrote in message news:<slrn9ol4i6.hro.trammell@haqq.hypersloth.net>...
> On 27 Aug 2001 05:36:52 -0700, soumitra bhattacharya wrote:
> > i.e.
> > 1||....
> > 2||..
> > 3||..
> > 4||...
> > 5-10||sum of mails read for 5 to 10||sum of mails deleted for5-10||.....
> > 11-20||...
> > 21-30||....
> > 31-40||...
> > 41-50||....
> > 50-whatever is max
> > so in first row will be data for people logged in once,
> > but in row 5-10 will be sum of data in rows 5,6,7,8,9,10 if they exist.
> > similarly for the row named 11-20 will be sum of data in rows 11..20 if they exist.
> > How do I do this.
> 
> One way is to use a hash to accumulate the sums:
> 
> my %sum;
> 
> while (<>)
> {
> 	my ($index,$data) = split(/\|\|/,$_); # or whatever
> 	my $key;
> 	for ($index)
> 	{
> 		$_ < 5  && do { $key = $_; last; };
> 		$_ < 11 && do { $key = "5-10"; last; };
> 		$_ < 21 && do { $key = "11-20"; last; };
> 		$_ < 31 && do { $key = "21-30"; last; }; 
> 		$_ < 41 && do { $key = "31-40"; last; }; 
> 		$_ < 51 && do { $key = "41-50"; last; }; 
> 		$key = "50+";
> 	}
>  $sum{$key} += $data;
> }
> 
> while (my($k,$v) = each %sum) { print "$k => $v\n" }
> 
> I'm sure there are other solutions, but this one isn't terrible.  :-)


------------------------------

Date: 28 Aug 2001 11:10:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: adding rows in a text file
Message-Id: <9mfu7d$jl1$1@mamenchi.zrz.TU-Berlin.DE>

According to John J. Trammell <trammell@haqq.hypersloth.invalid>:
> On 27 Aug 2001 05:36:52 -0700, soumitra bhattacharya wrote:
> > i.e.
> > 1||....
> > 2||..
> > 3||..
> > 4||...
> > 5-10||sum of mails read for 5 to 10||sum of mails deleted for5-10||.....
> > 11-20||...
> > 21-30||....
> > 31-40||...
> > 41-50||....
> > 50-whatever is max
> > so in first row will be data for people logged in once,
> > but in row 5-10 will be sum of data in rows 5,6,7,8,9,10 if they exist.
> > similarly for the row named 11-20 will be sum of data in rows 11..20
> if they exist.
> > How do I do this.
> 
> One way is to use a hash to accumulate the sums:
> 
> my %sum;
> 
> while (<>)
> {
> 	my ($index,$data) = split(/\|\|/,$_); # or whatever
> 	my $key;
> 	for ($index)
> 	{
> 		$_ < 5  && do { $key = $_; last; };
> 		$_ < 11 && do { $key = "5-10"; last; };
> 		$_ < 21 && do { $key = "11-20"; last; };
> 		$_ < 31 && do { $key = "21-30"; last; }; 
> 		$_ < 41 && do { $key = "31-40"; last; }; 
> 		$_ < 51 && do { $key = "41-50"; last; }; 
> 		$key = "50+";
> 	}
> 	$sum{$key} += $data;
> }
> 
> while (my($k,$v) = each %sum) { print "$k => $v\n" }
> 
> I'm sure there are other solutions, but this one isn't terrible.  :-)

Not at all.  It's also a nice demonstration of one of Perl's case-
like constructs.

The question "which interval is this number in" comes up quite a
bit.  Let me generalize a little:  Suppose $n intervals are given
as an ordered list @sep of separation points where the individual
(half-open) intervals are [$sep[$i], $sep[$i+1]).  The OP's list
of intervals would be represented by $sep = ( 5, 11, 21, 31, 41, 51);
We want to know which interval a given number $x is in, that is,
we want an index $i such that $sep[ $i] <= $x and $x < $sep[ $i+1].
If $x is below the first interval we shall return -1 and if it is
above the last one, we return $n - 1.  Taken slightly differently,
this means we want the largest index $i such that $sep[ $i] <= $x,
or -1 if no such index exists.  This leads to an immediate
implementation in terms of well-known Perl functions:  grep all
indexes with the desired property and take the last one:

    sub search_interval_0 {
        my $x = shift;
        my $i = ( grep $sep[ $_] <= $x, 0 .. @sep - 1)[ -1];
        defined $i ? $i : -1;
    }

While inefficient, it is certainly correct, and $key can now be
written

    qw( -4 5-10 11-20 21-30 31-40 41-50 50+)[ 1 + search_interval_0( $x)];

The worst inefficiency can be taken care of in the usual way: replace
grep with an explicit loop and quit the loop at the first match.
We must now loop over descending indexes, but that is no problem:

    sub search_interval_1 {
        my $x = shift;
        my $i;
        for ( reverse 0 .. @sep - 1 ) {
            $i = $_, last if $sep[ $_] <= $x;
        }
        defined $i ? $i : -1;
    }

This is still O(n) in the number of intervals.  If n is large, we
can do better using a binary search to find the interval in O( log n)
steps:

    sub search_interval_2 {
        my $x = shift;
        return -1 if $x < $sep[ 0];
        my ( $low, $high) = ( 0, @sep - 1);
        while ( $low < $high ) {
            my $mid = 1 + int( ( $low + $high)/2);
            $sep[ $mid] <= $x ? ( $low = $mid) : ( $high = $mid - 1);
        }
        $low;
    }

This isn't much longer than the other two, but it took far more time
to write.  Binary search is famous for its devilish detail.  It should
be about as fast as it gets with a pure Perl solution.

If you need it in industrial strength, well, I haven't looked but I
trust PDL has something to offer.

Anno
-- 
use overload '${}' => sub { \ 'Just '}, '@{}' => sub { [ 'another ']},
'%{}' => sub { { a => 'Perl '}}, '&{}' => sub { sub { print @_, 'hacker'}};
$plop = bless [];
$plop->( $$plop, $plop->[ 0], $plop->{ a});


------------------------------

Date: 28 Aug 2001 08:28:09 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Avoiding symbolic references.
Message-Id: <m3y9o4qsh2.fsf@mumonkan.sunstarsys.com>

Benjamin Goldberg <goldbb2@earthlink.net> writes:

> I suppose I should have mentioned I was looking for gamma, not e.
> 
> Anyway, the value is calculated as:
> 
> gamma = sum( i=1..inf, i*sum( j=2**i..2**(i+1)-1, (-1)**j / j ) );
> 
> which takes an ungodly long time to get even a few significant digits.

Did you try using google to find a better representation for gamma?

-- 
Joe Schaefer    "If you were plowing a field, which would you rather use? Two
                                strong oxen or 1024 chickens?"
                                               -- Seymour Cray



------------------------------

Date: 28 Aug 2001 12:33:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Avoiding symbolic references.
Message-Id: <9mg31s$o6u$2@mamenchi.zrz.TU-Berlin.DE>

According to Benjamin Goldberg  <goldbb2@earthlink.net>:
> Anno Siegel wrote:
> > 
> > According to Benjamin Goldberg  <goldbb2@earthlink.net>:
> > 
> > [calculating Euler's number]
> > 
> > > I suppose it doesn't matter much, anyway.  Having seen the amount of
> > > time it takes to calculate successive significant bits of euler's
> > > number, I've given up on calculating it to the log2(256!)
> > > significant bits I need to do what I want.
> > 
> > It can't be that bad.  Using e = 1 + 1/1! + ... + 1/n!, the error is
> > less than twice the first neglected term, so we want n = 256.  My
> > measly Pentium 90 does that in about 15 seconds.
> > 
> > > It's far easier and faster to download it off of a website.
> > 
> > That may still be true, if you count writing the program.
> 
> Umm, this is a different Euler's constant I'm calculating. ...

Uh... Errm... Okay.

Anno
-- 
use overload '${}' => sub { \ 'Just '}, '@{}' => sub { [ 'another ']},
'%{}' => sub { { a => 'Perl '}}, '&{}' => sub { sub { print @_, 'hacker'}};
$plop = bless [];
$plop->( $$plop, $plop->[ 0], $plop->{ a});


------------------------------

Date: 28 Aug 2001 03:57:02 -0700
From: amanpreet.sohi@sbs.siemens.co.uk (Pete Sohi)
Subject: Checking entries in a CSV file....?
Message-Id: <1ab8c4be.0108280257.7baffff3@posting.google.com>

Calling all code warriors!

Does anyone know how to process (e.g. open and count the number of
records in) a CSV file?

Presumably this is somewhat more complicated than simply counting the
number of lines in a normal txt file....?

Thanks in advance folks.

Pete.


------------------------------

Date: Tue, 28 Aug 2001 08:21:46 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Checking entries in a CSV file....?
Message-Id: <3B8B0E4A.6DFEBE0D@ce.gatech.edu>

Pete Sohi wrote:
> Does anyone know how to process (e.g. open and count the number of
> records in) a CSV file?
> 
> Presumably this is somewhat more complicated than simply counting the
> number of lines in a normal txt file....?


nope. just count the record seperators...you can set $/ to whatever you
are using as a separator, if it is not a newline.

-- 
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


------------------------------

Date: 28 Aug 2001 12:10:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CODE reference to member function of package Confusing..
Message-Id: <9mg1nv$o6u$1@mamenchi.zrz.TU-Berlin.DE>

According to Yves Orton <demerphq@hotmail.com>:
> nobull@mail.com wrote in message news:<u9snemzxuk.fsf@wcl-l.bham.ac.uk>...
> 
> > Komtanoo  Pinpimai <romerun@greezi.com> writes a question from the FAQ's..
> > So your question is "How can I pass a method?".
> 
> > This is a FAQ: "How can I pass/return a {Function, FileHandle, Array,
> > Hash, Method, Regex}?"
> 
> > > what should I do?
> > > suggestion please...
> 
> > I suggest that what you should do is check the FAQ before posting to
> > Usenet.
> 
> Just curious nobull, but do you think that after this comment CLPM
> will magically become free of newbies asking questions from the FAQ?
 
Why do you assume he expects that?  You probably never sweep your
floor because that doesn't magically make it dust-free forever.

> Also did it occur to you that perhaps his English is maybe not native?
> And that therefore reading/searching the faqs might not be so easy? 
> (Oh wait, the concept of not speaking English comes hard as hard to
> Brits as to Septic Tanks doesnt it....)

So fuckin what?  Are you saying clpm is easier to read than the Perl FAQ?

Yes, it's a handicap when your first language isn't English.  A few of
us have to live with that.  It applies to clpm as well as the FAQ and
a lot of documentation.  I you want to program, you need access to the
resources, no matter what.  Better get used to it.

> Ive seen the tagline that is attributed to you, the one about this
> being a discussion forum and answering questions is purely incidental.
>  Good comment.  But heres one for you:
> 
> If you dont like the fact that someone is asking questions that you'd
> rather not answer, THEN DONT! Dont bitch, and don't answer.

FAQ questions are easy to answer.  These are questions that we'd rather
not *see* in the first place.  This being a high-volume news group
makes the sheer number relevant.

The quality of a news group depends on the vigilance of its regulars.

Anno
-- 
use overload '${}' => sub { \ 'Just '}, '@{}' => sub { [ 'another ']},
'%{}' => sub { { a => 'Perl '}}, '&{}' => sub { sub { print @_, 'hacker'}};
$plop = bless [];
$plop->( $$plop, $plop->[ 0], $plop->{ a});


------------------------------

Date: Tue, 28 Aug 2001 14:59:48 +0200
From: Klaus Koch <kkoch@kxsu.de>
Subject: DBI connect string for Sybase Anywhere Studio
Message-Id: <9mg4b4$22jv8$1@ID-101758.news.dfncis.de>

hello!

I want to connect to a Sybase Anywhere Studio database with the DBD::ODBC 
module. The database server is called "limes" and the database is called 
"customers".

I dont know what to use in the connect string to get access to the database.

I tried:
$dbh = DBI->connect("dbi:ODBC:'uid=<user>;pwd=<pwd>;eng=limes'");
but I get a connection error.

what do i have to use to get access?

please help me.

thanks you!


------------------------------

Date: Tue, 28 Aug 2001 12:14:31 +0200
From: "Markus Linke" <markus.linke@ib.bankgesellschaft.de>
Subject: DBI Question
Message-Id: <9mfqrh$2u51@ecstasy.bb-data.de>

Hi,

I use the following script to get the SQL-Source of a view. The Problem is,
that I only get the first few characters of the View like "CREATE VIEW
murfi_xx AS select distinct data.ownindex, data.text, data.trandat,
data.ordrbuycod, stocks.Country_ISO, stocks.Murex_Id, data.trdqty,
data.tradmtchprc, data.stldate, data.t " but not the complete string.
$row[1] is empty. Any ideas?

Thanks,
Markus

$dbh = DBI->connect($dsn, $user, $pass,{ RaiseError => 1, AutoCommit => 0 })
            or die "Datenbankfehler";

$sth = $dbh->prepare("select text from syscomments where id =
object_id(\'murfi_$table\')");
$sth->execute;
@row=$sth->fetchrow_array;

my $selectstatement = $row[0];

$sth->finish;





------------------------------

Date: 28 Aug 2001 03:51:25 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: how to get named constants in Perl
Message-Id: <m11ylwo3te.fsf@halfdome.holdit.com>

>>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:

Martien> use const PI => 4 * atan2(1, 1);

Why the 4?  Why not just pick the right x,y?

use constant PI => atan2(0,-1);

print "Just another Perl hacker," if PI < 3.2;

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Tue, 28 Aug 2001 11:15:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to get named constants in Perl
Message-Id: <v1vmotsrabehf37li644um7h1jfhl4m4vf@4ax.com>

Martien Verbruggen wrote:

>our $PI;                # 'cuz we do like to run under strict
>*PI = \3.1415;
>$diameter = 2 * $PI * $radius;
>
>$PI just looks too much like a variable.

It IS a variable. Only, it's a read-only variable. That's what a
constant is suppoed to be, IMO.

>I find the inconvenience of not
>being able to interpolate in a string directly a price I'm willing to
>pay for having the constant look like one.

Hmmm... I don't like the inconvenience, without "use strict", of having
misspelled constants suddenly popping up as bareword strings.

Oh, so I should always use strict, anyway? There's a reason why it's not
on by default. It's inconvenient for smallish scripts. It may result in
what can be called "declaratitis", where setting up the script takes
more space than the actual code.

-- 
	Bart.


------------------------------

Date: 28 Aug 2001 13:19:19 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: how to get named constants in Perl
Message-Id: <cxcsnech1oo.fsf@tiamat.uio.no>

merlyn@stonehenge.com (Randal L. Schwartz) wrote:

> >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> 
> Martien> use const PI => 4 * atan2(1, 1);
> 
> Why the 4?  Why not just pick the right x,y?

Because that's what's suggested in the docs.  The "constant" man
page says

  use constant PI     => 4 * atan2 1, 1;

and the "perlsub" man page says

  sub PI () { 4 * atan2 1, 1 }      # As good as it gets,

> use constant PI => atan2(0,-1);

Sure, but this isn't suggested anywhere in the docs.

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


------------------------------

Date: Tue, 28 Aug 2001 11:29:15 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9omvm8.u7r.bernard.el-hagin@gdndev25.lido-tech>

On 28 Aug 2001 13:19:19 +0200, Peter J. Acklam <jacklam@math.uio.no> wrote:
>merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>
>> >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
>> 
>> Martien> use const PI => 4 * atan2(1, 1);
>> 
>> Why the 4?  Why not just pick the right x,y?
>
>Because that's what's suggested in the docs.  The "constant" man
>page says
>
>  use constant PI     => 4 * atan2 1, 1;
>
>and the "perlsub" man page says
>
>  sub PI () { 4 * atan2 1, 1 }      # As good as it gets,
>
>> use constant PI => atan2(0,-1);
>
>Sure, but this isn't suggested anywhere in the docs.

So?

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


------------------------------

Date: 28 Aug 2001 13:34:31 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: how to get named constants in Perl
Message-Id: <cxclmk4h0zc.fsf@tiamat.uio.no>

bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:

> Peter J. Acklam <jacklam@math.uio.no> wrote:
> 
> > merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >
> > > >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> > > 
> > > Martien> use const PI => 4 * atan2(1, 1);
> > > 
> > > Why the 4?  Why not just pick the right x,y?
> >
> > Because that's what's suggested in the docs.  The "constant"
> > man page says
> >
> >  use constant PI     => 4 * atan2 1, 1;
> >
> > and the "perlsub" man page says
> >
> >  sub PI () { 4 * atan2 1, 1 }      # As good as it gets,
> >
> > > use constant PI => atan2(0,-1);
> >
> > Sure, but this isn't suggested anywhere in the docs.
> 
> So?

So, that's probably why he used "4 * atan2(1, 1)" rather than
"atan2(0,-1)".

It's documented, it works, so he probably didn't think much more
about it.

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


------------------------------

Date: Tue, 28 Aug 2001 11:49:52 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9on0so.u7r.bernard.el-hagin@gdndev25.lido-tech>

On 28 Aug 2001 13:34:31 +0200, Peter J. Acklam <jacklam@math.uio.no> wrote:
>bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:
>
>> Peter J. Acklam <jacklam@math.uio.no> wrote:
>> 
>> > merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>> >
>> > > >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
>> > > 
>> > > Martien> use const PI => 4 * atan2(1, 1);
>> > > 
>> > > Why the 4?  Why not just pick the right x,y?
>> >
>> > Because that's what's suggested in the docs.  The "constant"
>> > man page says
>> >
>> >  use constant PI     => 4 * atan2 1, 1;
>> >
>> > and the "perlsub" man page says
>> >
>> >  sub PI () { 4 * atan2 1, 1 }      # As good as it gets,
>> >
>> > > use constant PI => atan2(0,-1);
>> >
>> > Sure, but this isn't suggested anywhere in the docs.
>> 
>> So?
>
>So, that's probably why he used "4 * atan2(1, 1)" rather than
>"atan2(0,-1)".
>
>It's documented, it works, so he probably didn't think much more
>about it.

Yes, but the way you said "Sure, but this isn't suggested anywhere in
the docs" made it seem like you don't think Randal's method is valid
only because it doesn't appear in the docs. If that's not what you meant
then forget about the whole thing. If it *is* what you meant then it's
a ridiculous statement and I didn't want it to go without comment to
that effect.

Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'


------------------------------

Date: 28 Aug 2001 13:55:47 +0200
From: jacklam@math.uio.no (Peter J. Acklam)
Subject: Re: how to get named constants in Perl
Message-Id: <cxcr8twflfg.fsf@tiamat.uio.no>

bernard.el-hagin@lido-tech.net (Bernard El-Hagin) wrote:

> Peter J. Acklam <jacklam@math.uio.no> wrote:
>
> > It's documented, it works, so he probably didn't think much
> > more about it.
> 
> Yes, but the way you said "Sure, but this isn't suggested
> anywhere in the docs" made it seem like you don't think Randal's
> method is valid only because it doesn't appear in the docs.

Oh, I see.  Perhaps I was unclear.  Randal's method certainly is
valid.  All I wanted to do was to try to explain why someone had
used the other method.

> If that's not what you meant then forget about the whole thing.

I will.  :-)

> If it *is* what you meant then it's a ridiculous statement and I
> didn't want it to go without comment to that effect.

It would have been silly, yes, and your comment would be apt.

Peter

-- 
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;


------------------------------

Date: 28 Aug 2001 13:00:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to get named constants in Perl
Message-Id: <9mg4lr$o6u$3@mamenchi.zrz.TU-Berlin.DE>

According to Randal L. Schwartz <merlyn@stonehenge.com>:
> >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
> 
> Martien> use const PI => 4 * atan2(1, 1);
> 
> Why the 4?  Why not just pick the right x,y?
> 
> use constant PI => atan2(0,-1);

The 4 has tradition.  The standard series for the arctan function
converges reasonably well for x = 1, and the summands are easily
calculated (they are the inverses of the odd numbers with alternating
signs).  That makes atan(1) a schoolbook method to calculate pi.

Anno
-- 
use overload '${}' => sub { \ 'Just '}, '@{}' => sub { [ 'another ']},
'%{}' => sub { { a => 'Perl '}}, '&{}' => sub { sub { print @_, 'hacker'}};
$plop = bless [];
$plop->( $$plop, $plop->[ 0], $plop->{ a});


------------------------------

Date: Tue, 28 Aug 2001 13:54:00 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: Java mucks up split
Message-Id: <9mg0fu02qs8@enews4.newsguy.com>


"Trewth Seeker" <trewth_seeker@yahoo.com> wrote in message
news:d690a633.0108280002.6054b2b5@posting.google.com...
> That's just dumb, and misses the whole point of the limit.  This is
> going to lead to confusion and cause some people to think that Perl is
> just as broken, since Java's split is taken from Perl.  What can be
> done to get Sun to do it right?

It is quite dumb actually, cos it's easier to take the first two elements,
than extract from the 3rd match onwards.  However, just because java seems
to be adding regexp, it doesn't really mean that java has to become Perl.
Tcl's script incidentally does not support a limit.

B.




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1636
***************************************


home help back first fref pref prev next nref lref last post