[23233] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5454 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 7 00:05:48 2003

Date: Sat, 6 Sep 2003 21:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 6 Sep 2003     Volume: 10 Number: 5454

Today's topics:
    Re: Active Perl, Windows scheduler, regular task... <minceme@start.no>
    Re: AI::GA <NOSPAM@bigpond.com>
        DBI Output Help (Tom)
    Re: DBI Output Help <mbudash@sonic.net>
        Displaying Excel from my CGI <kbass@midsouth.rr.com>
    Re: Displaying Excel from my CGI <postmaster@castleamber.com>
        Great Book on Web Services <balachandra@covansys.co.in>
        How do I count blocks of characters in a string variabl (Researcher)
    Re: How do I count blocks of characters in a string var <pinyaj@rpi.edu>
    Re: How do I count blocks of characters in a string var <krahnj@acm.org>
    Re: How do I count blocks of characters in a string var <noreply@gunnar.cc>
        How do I count keys in a BerkeleyDB *quickly* (using DB (Damon Hastings)
    Re: libxml-perl-0.07 and perl5.8.0 - fails test <jwillmore@cyberia.com>
    Re: Order of evaluation of expressions (David Combs)
    Re: Order of evaluation of expressions (David Combs)
    Re: Order of evaluation of expressions (David Combs)
    Re: Order of evaluation of expressions <sholden@staff.cs.usyd.edu.au>
    Re: Order of evaluation of expressions <sholden@staff.cs.usyd.edu.au>
    Re: Order of evaluation of expressions <REMOVEsdnCAPS@comcast.net>
    Re: PHP vs Perl <REMOVEsdnCAPS@comcast.net>
    Re: read VB file with Perl <david-del@del-nonspiritual.com>
    Re: read VB file with Perl <krahnj@acm.org>
    Re: splitting an array (Jay Tilton)
    Re: splitting an array <go@away.spam>
        Strange behavior after reading big file <jill_krugman@yahoo.com>
    Re: Strange behavior after reading big file (Tad McClellan)
    Re: Strange behavior after reading big file <jill_krugman@yahoo.com>
    Re: View NG with Net::NNTP (Chas Friedman)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 6 Sep 2003 22:03:35 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: Active Perl, Windows scheduler, regular task...
Message-Id: <bjdljn$lg5$1@troll.powertech.no>

Alan J. Flavell <flavell@mail.cern.ch> wrote:

> Thanks! - so I've defined the windows scheduler task to be
>
>    wperl c:\path\to\script.pl
>
> and can confirm that it works fine, thanks.
>
>
> I'm still wondering whether I'm heading down the wrong track and ought
> to be looking to define a script as a system service, but I think this
> approach will work.  Thanks for the help!

Apropos running perl as a windows service. 

I've read that activestates perl dev-kit compiles perlscripts into
executables that can be run as a service. Are there free alternatives?

-- 
Vlad


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

Date: Sun, 7 Sep 2003 12:57:45 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: AI::GA
Message-Id: <bje6qu$hqhv9$1@ID-202028.news.uni-berlin.de>

"Arthur T. Murray" <uj797@victoria.tc.ca> wrote in message
news:3f5a0fa7@news.victoria.tc.ca...
> AI::GA - a general genetic algorithm library is at
> http://www.skamphausen.de/software/AI/ga.html from

Yes .. so???  A quick search reveals

"Charlton Wilbur" <cwilbur@mithril.chromatico.net> wrote in message
news:87iso73wt7.fsf@mithril.chromatico.net...
>
> Arthur T. Murray is a net.kook.
>
> Charlton


gtoomey




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

Date: 6 Sep 2003 12:56:16 -0700
From: ompers@hotmail.com (Tom)
Subject: DBI Output Help
Message-Id: <f4144fab.0309061156.77e83ec1@posting.google.com>

Hello.

I am learning Perl and have decided to create a web page that has
dropdowns populated by a postgreSQL DB.  I've been able to do this and
the page looks fine but the code is awful.  A chunk of the code is
posted below; can anyone suggest a way to clean this up and make it
more efficient?  Namely, I am trying to consolidate the actual
population of the <SELECT> into one loop, and figure out a way to get
rid of the ugly "$i < scalar(@array)" line.

This all works, but I'm still learning Perl and haven't figured out
how to make it work good!

Thanks,
Tom

CODE BELOW:
===========


#!/opt/perl/bin/perl -wT
use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;

my $dbh = DBI->connect( "dbi:Pg:dbname=web" ) || die;
my @a = ('groupdescription','groups');
my @b = ('role','servers_role');
my $sth1 = $dbh->prepare("Select $a[0] from $a[1] order by $a[0]");
my $sth2 = $dbh->prepare("Select $b[0] from $b[1] order by $b[0]");

$sth1->execute;
$sth2->execute;

print $q->header,
      $q->start_html,
      $q->startform,
      "<table><Tr><td>$a[0]</td>",
      "<td><Select name=\"$a[0]\">";

while( @row1 = $sth1->fetchrow ) {
    for( $i = 0; $i < scalar(@row1); $i++ ) {
        print "<option value=\"$row1[$i]\">$row1[$i]";
    }
}
print "</Select></td></Tr>",
      "<Tr><td>$b[0]</td>",
      "<td><Select name=\"$b[0]\">";

while( @row2 = $sth2->fetchrow ) {
    for( $i = 0; $i < scalar(@row2); $i++ ) {
        print "<option value=\"$row2[$i]\">$row2[$i]";
    }
}
print "</Select></td></Tr></table></body></html>";


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

Date: Sat, 06 Sep 2003 21:01:23 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: DBI Output Help
Message-Id: <mbudash-EF53D6.14012206092003@typhoon.sonic.net>

In article <f4144fab.0309061156.77e83ec1@posting.google.com>,
 ompers@hotmail.com (Tom) wrote:

> Hello.
> 
> I am learning Perl and have decided to create a web page that has
> dropdowns populated by a postgreSQL DB.  I've been able to do this and
> the page looks fine but the code is awful.  A chunk of the code is
> posted below; can anyone suggest a way to clean this up and make it
> more efficient?  Namely, I am trying to consolidate the actual
> population of the <SELECT> into one loop, and figure out a way to get
> rid of the ugly "$i < scalar(@array)" line.
> 
> This all works, but I'm still learning Perl and haven't figured out
> how to make it work good!
> 
> Thanks,
> Tom
> 
> CODE BELOW:
> ===========
> 
> 
> #!/opt/perl/bin/perl -wT

use strict;

> use DBI;
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> 
> my $q = new CGI;
> 
 .
 .
 .
> while( @row1 = $sth1->fetchrow ) {
>     for( $i = 0; $i < scalar(@row1); $i++ ) {
>         print "<option value=\"$row1[$i]\">$row1[$i]";
>     }
> }

while( my @row1 = $sth1->fetchrow_array ) {
    print qq|<option value="$row1[0]">$row1[0]|;
}

 .
 .
 .


hth-

-- 
Michael Budash


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

Date: Sat, 06 Sep 2003 22:07:18 GMT
From: <kbass@midsouth.rr.com>
Subject: Displaying Excel from my CGI
Message-Id: <qUs6b.3466$WW5.3036@clmboh1-nws5.columbus.rr.com>

I have created a table from my CGI program with data coming from Postgres
and I want to now display this table as an Excel file. How can this be done?
Thanks!

Kevin




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

Date: Sun, 07 Sep 2003 00:19:02 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Displaying Excel from my CGI
Message-Id: <1062886845.393865@halkan.kabelfoon.nl>

kbass@midsouth.rr.com wrote:

> I have created a table from my CGI program with data coming from Postgres
> and I want to now display this table as an Excel file. How can this be done?
> Thanks!

Turn it into csv or tsv (tab separated values) which can be imported 
into Excel.

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Sat, 06 Sep 2003 19:02:00 GMT
From: "Balachandra" <balachandra@covansys.co.in>
Subject: Great Book on Web Services
Message-Id: <Iaq6b.5238$lD1.132@newssvr33.news.prodigy.com>

http://www.amazon.com/exec/obidos/ASIN/1558609008/india




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

Date: 6 Sep 2003 15:24:01 -0700
From: phb2911@hotmail.com (Researcher)
Subject: How do I count blocks of characters in a string variable?
Message-Id: <2d337d68.0309061424.6e63ab0@posting.google.com>

I'm trying to create a code to count a certain character in a string,
lets say that I want to know how many letters "o" there are in the
text "The book is yellow", I'd use the following code:

$text = "The book is yellow";
@characters = split (//,$text);
foreach $char (@characters){
   if ($char eq "o"){
      $count++;
   }
}

Very easy, but I think this is a lot of code for such a simple task,
there's got to be a simpler way to do this, besides, what if I want to
count a block of characters instead of one only (e.g. how many "el"
there are in $text)? How do I do this?

I hope someone can help me with this.


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

Date: Sat, 6 Sep 2003 18:29:07 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: How do I count blocks of characters in a string variable?
Message-Id: <Pine.SGI.3.96.1030906182828.74834A-100000@vcmr-64.server.rpi.edu>

On 6 Sep 2003, Researcher wrote:

>I'm trying to create a code to count a certain character in a string,
>lets say that I want to know how many letters "o" there are in the
>text "The book is yellow", I'd use the following code:
>
>$text = "The book is yellow";
>@characters = split (//,$text);
>foreach $char (@characters){
>   if ($char eq "o"){
>      $count++;
>   }
>}

If you just want to count the number of times a character occurs in a
string, use the tr/// operator.

  $o_count = $string =~ tr/o//;

Read 'perldoc perlop' for more on tr///.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sat, 06 Sep 2003 22:45:21 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How do I count blocks of characters in a string variable?
Message-Id: <3F5A6390.7033158C@acm.org>

Jeff 'japhy' Pinyan wrote:
> 
> On 6 Sep 2003, Researcher wrote:
> 
> >I'm trying to create a code to count a certain character in a string,
> >lets say that I want to know how many letters "o" there are in the
> >text "The book is yellow", I'd use the following code:
> >
> >$text = "The book is yellow";
> >@characters = split (//,$text);
> >foreach $char (@characters){
> >   if ($char eq "o"){
> >      $count++;
> >   }
> >}
> 
> If you just want to count the number of times a character occurs in a
> string, use the tr/// operator.
> 
>   $o_count = $string =~ tr/o//;
> 
> Read 'perldoc perlop' for more on tr///.

Or if 'o' is in a variable you can do this:

my $char = 'o';

$count = () = $string =~ /\Q$char/g;


John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 07 Sep 2003 00:49:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do I count blocks of characters in a string variable?
Message-Id: <bjdong$hp5o9$1@ID-184292.news.uni-berlin.de>

Researcher wrote:
> I'm trying to create a code to count a certain character in a 
> string, lets say that I want to know how many letters "o" there are
> in the text "The book is yellow",

<snip>

> what if I want to count a block of characters instead of one only
> (e.g. how many "el" there are in $text)?

This method works with both single characters and strings:

     $text = "The book is yellow";
     $count++ while $text =~ /o/g;

Btw, you asked a FAQ. This is where you should have looked up the
answer:

     perldoc -q count

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 5 Sep 2003 20:13:22 -0700
From: damonhastings@yahoo.com (Damon Hastings)
Subject: How do I count keys in a BerkeleyDB *quickly* (using DB_File)?
Message-Id: <76c7896d.0309051913.6bf1afb7@posting.google.com>

I have a berkeley db which I'm accessing via the DB_File interface (a
btree).  I would like a quick way to count how many keys are in the
file.  If I just use "scalar keys %hash", then it takes forever!  (The
file has millions of keys.)  Can anyone help me?



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

Date: Sun, 07 Sep 2003 03:28:12 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: libxml-perl-0.07 and perl5.8.0 - fails test
Message-Id: <20030906232812.120a80d0.jwillmore@cyberia.com>

On Sat, 6 Sep 2003 22:34:08 +1000
"dj" <thecommissioner@hotmail.com> wrote:
> The fail does not give any specific information about why the
> failure occurs, except that it is test 11 of 11 in t/stream.t
> I tried running 'perl t/stream.t' and it gave even less info: Not
> OK! I don't have the source code in front of me at the moment, but
> to be honest I didnt really make much sense of it :(
> The mailing archive I read suggested that it _may_ have been
> something to with Unicode compatability, but as I mentioned, I only
> found a single reference to this.
> 
> I have been wrestling with this for a while:  all I really want to
> do is put the text content from an xml file into an easily readable
> data structure. Am I going about this the wrong way?

Are you building using CPAN or by hand?  Try it by hand (perl
Makefile.PL;make;make test;make install).  This may shed _some_ light
on what's going on.

If you've done this already, you could email the author. 

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
The best way to make a fire with two sticks is to make sure one
<of them is a match.   -- Will Rogers 


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

Date: Sun, 7 Sep 2003 01:07:34 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Order of evaluation of expressions
Message-Id: <bje0cm$opb$1@reader2.panix.com>

In article <Xns93DBD96543052sdn.comcast@206.127.4.25>,
Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
>-----BEGIN xxx SIGNED MESSAGE-----
>Hash: SHA1
>
SNIP
>
>- From Harbison & Steele, 4ed, p 227:
>
><blockquote>
>    To control the order of evaluation, the programmer can 
>    use assignments to temporary variables.  However, a good
>    optimizing compiler might even rearrange computations
>    such as this:
>
>        int temp1, temp2;
>        ...
>        /* Compute q=(a+b)+(c+d), exactly that way. */
>        temp1 = a+b;
>        temp2 = c+d;
>        q = temp1 + temp2;
></blockquote>
>
>>      (For something THAT simple, I would keep it one line and use
>>      parens to force the order I want, even if it matches the
>>      language. The difference in the compile step is negligible.)
>
>Once again, in a language such as C in which order of evaluation is not 
>defined, parentheses do *not* affect order of evaluation!  They affect 
>precedence only.

From the zero-indentation of those last three lines,
I assume that it's *you* that's saying it, not Steele (or Harbison).

Your statement, that in C the parens do not force the
order of calculation to follow the paren's order and nesting,
that's so contrary to everything I've ever read about C
or any other language -- that I'm asking you (or someone)
to please say a bit more about it.

I mean, is that claim in the language-definition?

Or just in some (weird) compiler, but not in (many) others?

Or might it be an option *to* some compiler?

Or have I just been reading incorrectly, for years,
every ref I've seen to C (and other languages too, perhaps)?

*Very* puzzled (that I'm the first to follow-up on this post).

THANKS!

(and if I'm wrong, please accept, in advance, my apologies.)

David






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

Date: Sun, 7 Sep 2003 01:29:17 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Order of evaluation of expressions
Message-Id: <bje1ld$p36$1@reader2.panix.com>

In article <3F427641.DB7094DD@boeing.com>,
Michael P. Broida <michael.p.broida@boeing.com> wrote:
>Tony Curtis wrote:
>> 
>> >> On Mon, 18 Aug 2003 21:48:51 GMT,
>> >> "Michael P. Broida" <michael.p.broida@boeing.com> said:
>> 
>> > "Eric J. Roode" wrote:
>> >>  "Michael P. Broida" <michael.p.broida@boeing.com>
>> >> wrote in news:3F412BEA.DC9CA189@boeing.com:
>> >>
>> >> > Unless I'm missing something in your comment, it
>> >> seems the > question boils down to "what precedence do
>> >> subroutine/function > calls have?"
>> >>
>> >> No, not really.  Precedence is different than order of
>> >> evaluation.  In C, for example, precedence is
>> >> well-defined, but order of evaluation is famously
>> >> undefined.

Earlier, I replied to an article in this thread
that I believed said that even with parentheses,
in C the compiler could legally rearrange even
that -- implied with that is that of course
the *algebraic* result came out the same.

(I sure hope it included the word "parentheses",
because that's what I based my unbelieving reply on.)

Anyway, woe to the fledgling numerical analyst
who codes:

z = a + b + c + d + e + f

, where, in alphebetical order (a-f) the
values are:

 .00000000333

(same for b, c, d, and e)

3.0000000000

, where the size of the mantissa in the floating-point
word makes a difference, ie compared with it
being *calculated* in *this* order:

z = a + b + f + c + d + e

Worrying ahead of time about optimizers changing
the order on you, you'd have to write it, maybe,
like this:

z  =  (a + (b + (c + (d + (e + (f))))))

, at least in the case where, suppose, a is smallest (eg .00000001),
b is next smallest (eg .0000006), and so on.

If the compiler could freely screw *this* around, even
with the parens -- horrors.


(Now I'm hoping that I did misread that post!)

David




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

Date: Sun, 7 Sep 2003 01:36:35 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: Order of evaluation of expressions
Message-Id: <bje233$p6s$1@reader2.panix.com>

In article <Xns93DCE1251F9F8sdn.comcast@206.127.4.25>,
Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
>-----BEGIN xxx SIGNED MESSAGE-----
>Hash: SHA1
>
>"John W. Krahn" <krahnj@acm.org> wrote in
>news:3F42BCBC.276477FC@acm.org: 
>
>> Abigail wrote:
>>> 
>>> John W. Krahn (krahnj@acm.org) wrote on MMMDCXL September MCMXCIII in
>>> <URL:news:3F417BDC.7F24A9F3@acm.org>:
>>> ==
>>> ==  Just going by perlop.pod, shift() is a named unary operator which
>>> has ==  lower precedence than . and . is left associative which would
>>> mean it ==  would evaluate the left side first.  Correct me if I'm
>>> wrong.  :-) 
>>> 
>>> Precedence isn't the same as order of evaluation.
>> 
>> Yes I know.  What I was trying to say is that the concatenation
>> operator is left associative so that:
>> 
>> shift(@a) . shift(@b) . shift(@c) . shift(@d)
>> 
>> will be always be evaluated as:
>> 
>> ( ( shift(@a) . shift(@b) ) . shift(@c) ) . shift(@d)
>
>Parentheses don't control order of evaluation.  Associativity is more 
>related to precedence than to order of evaluation.

THERE IT IS AGAIN, THAT STATEMENT! (this time not referring to C, though)

If true, I guess that in perl you cannot add up wildly-differently-sized
reals (er, numbers) (where you know which are big and which are small).

What, have to write separate assignment statements, each one
growing by the next one of a, b, c, d, etc, being thus forced
to recode the only *intuitively* numerical-analysisly-correct:

z  =  (a + (b + (c + (d + (e + (f))))))


David




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

Date: 7 Sep 2003 02:11:51 GMT
From: Sam Holden <sholden@staff.cs.usyd.edu.au>
Subject: Re: Order of evaluation of expressions
Message-Id: <slrnbll4v7.3cm.sholden@staff.cs.usyd.edu.au>

On Sun, 7 Sep 2003 01:36:35 +0000 (UTC), David Combs <dkcombs@panix.com> wrote:

[snip order or evaluation and precendence being different]

> 
> THERE IT IS AGAIN, THAT STATEMENT! (this time not referring to C, though)
> 
> If true, I guess that in perl you cannot add up wildly-differently-sized
> reals (er, numbers) (where you know which are big and which are small).
> 
> What, have to write separate assignment statements, each one
> growing by the next one of a, b, c, d, etc, being thus forced
> to recode the only *intuitively* numerical-analysisly-correct:
> 
> z  =  (a + (b + (c + (d + (e + (f))))))

Associativity and prededence have almost *nothing* to do with order of
evaluation. The order of evaluation in that example is irrelevant (assuming
those letters represent single numeric values.

Order of evaluation comes in, when you do something like:

z = (a() + ((b() + (c() + (d() + (e() + (f())))))))

The result will be as expected, in that e() + f() will be calculated, and then
d() + <prior result> and so on and so on. 

Order of evaluation defined the order in which the functions a(), b(), .. f()
will be called. 

They could be called as they are needed, in which case e() and f() will be
called first, then d(), then c(), then b(), then a(). Or they all be called
before the calculation begins arbitrary order. Or some micture of the two.

Order of evaluation only matters when those function have side effect, or
when when things like a++ are used, which also have side effects.

So in the perl example from above with some modification to make the
side effects of the shift function matter:

*a = *b = *c = *c; #make the side effects matter...
@a = qw/a b c d/;
$first = (shift(@a) . (shift(@b)  . (shift(@c)  . shift(@d))));

@a = qw/a b c d/;
$second = shift(@c)  . shift(@d);
$second = shift(@b) . $second;
$second = shift(@a) . $second;
print "first: $first; second: $second\n";

Both $first and $second use the same associativity and precedence. However,
they have different order of evaluations.

From the output I get perl is evaluating the shift()s from left to right,
even though the parenthesis mean it is calculating the result from right
to left.

The calculation will be done in the order indicated by the precendence
and parenthesis. However, the evaluation of the individual terms is done
in a different (possibly arbitrary or random) order. The evaluation of
individual terms can *not* affect the result, unless there are
*side effects*.

-- 
Sam Holden



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

Date: 7 Sep 2003 02:15:26 GMT
From: Sam Holden <sholden@staff.cs.usyd.edu.au>
Subject: Re: Order of evaluation of expressions
Message-Id: <slrnbll55u.3cm.sholden@staff.cs.usyd.edu.au>

On 7 Sep 2003 02:11:51 GMT, Sam Holden <sholden@staff.cs.usyd.edu.au> wrote:
> 
> So in the perl example from above with some modification to make the
            ^^^^^^^^^^^^^^^^^^^^^^^

Which I trimmed and hence isn't there...
 
> *a = *b = *c = *c; #make the side effects matter...
                 ^^
Should be *d :
*a = *b = *c = *d;

Which I did when I tested the code, but failed to copy the modified code
back to my posting. 

-- 
Sam Holden



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

Date: Sat, 06 Sep 2003 22:12:29 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Order of evaluation of expressions
Message-Id: <Xns93EEEC3E82233sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

dkcombs@panix.com (David Combs) wrote in news:bje0cm$opb$1
@reader2.panix.com:

> In article <Xns93DBD96543052sdn.comcast@206.127.4.25>,
> Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
>>-----BEGIN xxx SIGNED MESSAGE-----
>>Hash: SHA1
>>
> SNIP
>>
>>- From Harbison & Steele, 4ed, p 227:
>>
>><blockquote>
>>    To control the order of evaluation, the programmer can 
>>    use assignments to temporary variables.  However, a good
>>    optimizing compiler might even rearrange computations
>>    such as this:
>>
>>        int temp1, temp2;
>>        ...
>>        /* Compute q=(a+b)+(c+d), exactly that way. */
>>        temp1 = a+b;
>>        temp2 = c+d;
>>        q = temp1 + temp2;
>></blockquote>
>>
>>>      (For something THAT simple, I would keep it one line and use
>>>      parens to force the order I want, even if it matches the
>>>      language. The difference in the compile step is negligible.)
>>
>>Once again, in a language such as C in which order of evaluation is not 
>>defined, parentheses do *not* affect order of evaluation!  They affect 
>>precedence only.
> 
> From the zero-indentation of those last three lines,
> I assume that it's *you* that's saying it, not Steele (or Harbison).

Yes, that was me.

 
> Your statement, that in C the parens do not force the
> order of calculation to follow the paren's order and nesting,
> that's so contrary to everything I've ever read about C
> or any other language -- that I'm asking you (or someone)
> to please say a bit more about it.

Sure.

I think the confusion here is that many people are using the fact that 
parentheses *group* expressions to mean that the expressions must be 
evaluated in some particular order. 

Let's take a simple example, again in C:

    a = b + c * d;

Let's further suppose that before this statement, a is 1, b is 2, c is 3, 
and d is 4.

Someone who didn't know about precedence might think that the result 
would be an assignment of 20 to a (b + c is 2 + 3 which is 5, multiplied 
by 4 is 20).  But of course multiplication has a higher precedence, so 
the actual result is an assignment of 14 to a (c * d is 3 * 4 which is 
12, added to 2 is 14).

Now it is clear that the multiplication must happen first, before the 
addition.  This is because of precedence (and associativity, although 
that does not enter into this particular example).  Right.  Also, if you 
use parentheses to regroup the expression:

    a = (b + c) * d;

then it is now clear that the addition must happen first, before the 
addition.

This is the source of the confusion, and why you think that parentheses 
control order of evaluation.  They do not.  They override (or refine, 
depending on how you want to look at it) the precedence of operations, 
which does have some effect on the order in which the operators are 
evaluated.

However: what is explicitly NOT guaranteed is the order of evaluation of 
the expressions a, b, c, d.  In the above examples they are simple 
variables.  Nothing about the C standard, nor 30 years of C's existence, 
dictates anything about the order in which those variables are fetched 
from memory.

So what?

Well, perhaps those variables are declared volatile, and map to I/O 
devices.  Which value gets fetched first could have a drastic effect on 
the result of the expression.  (Think of tied variables in Perl).  Or to 
take a more common example, let's change the expression slightly to:

    a = b() + c() * d();

Now, as we have seen before, the result of the function call c() is first 
multiplied by the result of the function call d(), and that product is 
then added to the result of the function call b().  BUT: There is no -- 
absolutely NO -- guarantee or standard or rule as to which function gets 
called first, second, or third.  Perhaps the compiler looks at the 
expression and sees that three calls are needed, and invokes b(), then 
c(), then d(), then multiplies the (stored) results of c() and d(), then 
adds the (stored) result of b().  Perhaps it invokes the functions in a 
different order.

If the functions have side effects, and especially if they have side 
effects that affect each other (note grammatically correct usage of 
"affect" and "effect"!), then the results are, as explicitly stated by 
the ANSI and ISO C standards, *undefined*.

Much has been made of this in the C newsgroups; see the comp.lang.c FAQ 
entry about the expression "i = i++".

Now, how does this relate to Perl?

I had been under the impression that Perl's order of evaluation was well-
defined, but that impression seems to have been incorrect.  As far as I 
can tell, there is no defined O of E in Perl, so the same caveats above 
seem to apply to the Perl language.

But I'm not sure.

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP1qiUmPeouIeTNHoEQJy/ACgqu3wokJBFG1DXONvu+VToAavHaoAnA1q
nxf14p5AFoT9Sob4UciQyN06
=1I6d
-----END PGP SIGNATURE-----


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

Date: Sat, 06 Sep 2003 13:12:37 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: PHP vs Perl
Message-Id: <Xns93EE9099FE9D7sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

John Taylor-Johnston <taylorjo@collegesherbrooke.qc.ca> wrote in 
news:3F593E88.23029739@collegesherbrooke.qc.ca:

> Comparison study. Can this be done in Perl? How many lines?
> 
> <?php
> $display_start = "2003-09-01";
> $display_end = "2003-09-31";
> 
> echo "testing<br>";
> 
> $stuff = "$display_start - $display_end<br>";
> 
> if((date("Y-m-d") >= $display_start) && (date("Y-m-d") <= 
$display_end)){
>         print($stuff);
> }else{
> echo "Date expired: ".date("Y-m-d");
> }
> ?>
> 

Almost exactly the same:

  use Time::Format;

  $display_start = "2003-09-01";
  $display_end = "2003-09-31";   # Did you really mean 30?
  
  print "testing<br>";
  
  $stuff = "$display_start - $display_end<br>";
  
  if(($time{"yyyy-mm-dd"} ge $display_start) && ($time{"yyyy-mm-dd"} le 
$display_end)){
          print($stuff);
  }else{
  print "Date expired: $time{'yyyy-mm-dd'}";
  }



- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP1ojomPeouIeTNHoEQJG0ACgzFDEgt5E5GRmj8v5hR+mW8vDH34AoPEB
FD85q2Q0QrCTqtNXQZE0tTPn
=3Hkg
-----END PGP SIGNATURE-----


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

Date: Sat, 06 Sep 2003 21:02:53 -0500
From: David McDivitt <david-del@del-nonspiritual.com>
Subject: Re: read VB file with Perl
Message-Id: <4r3llvs749kahah09enfr2e37hf7lfpha4@4ax.com>

Thanks to Vlad Tepes for getting me going on this. My Perl program is
below. Neat thing is Perl unpacks double floating point values straight
out of the input buffer. The date data type in VB is a double with days
to the left of the decimal and time to the right. Anyone know how to
convert double values to a date string?

use warnings;
use strict;

my $headerlength = 823;
my $stringcount = 61;
my $headertemplate = <<TMPL;
   d    #LastScanTime
   d    #NextExecuteTime
   v    #NextExecuteTimeSet As Integer
   V    #MinutesToRun As Long
   d    #TaskID
   A4   #ID As String * 4
   A    #ProcScheduler As String * 1
   A30  #ProcName As String * 30
   v    #Active As Integer
   v    #PassArguments As Integer
   A4   #OwnSection As String * 4
   A4   #OwnUnit As String * 4
   A256 #Executable As String * 256
   v    #ExecutableType As Integer
TMPL
my ($template, $buf, $j, @strings, $stringtotal);

open DESCRIPFILE, "<0001.desc";
read DESCRIPFILE, $buf, $headerlength;
my ($LastScanTime,
    $NextExecuteTime,
    $NextExecuteTimeSet,
    $MinutesToRun,
    $TaskID,
    $ID,
    $ProcScheduler,
    $ProcName,
    $Active,
    $PassArguments,
    $OwnSection,
    $OwnUnit,
    $Executable,
    $ExecutableType,
    @pointers) = unpack $headertemplate."VV"x$stringcount, $buf;
$template = "";
for ($j=$stringcount; $j<@pointers; $j++) {
   $template .= "A".$pointers[$j];
   $stringtotal += $pointers[$j];
   }
read DESCRIPFILE, $buf, $stringtotal;
@strings = unpack $template, $buf;
close DESCRIPFILE;

print "LastScanTime = ",       $LastScanTime,       "\n";
print "NextExecuteTime = ",    $NextExecuteTime,    "\n";
print "NextExecuteTimeSet = ", $NextExecuteTimeSet, "\n";
print "MinutesToRun = ",       $MinutesToRun,       "\n";
print "TaskID = ",             $TaskID,             "\n";
print "ID = ",                 $ID,                 "\n";
print "ProcScheduler = ",      $ProcScheduler,      "\n";
print "ProcName = ",           $ProcName,           "\n";
print "Active = ",             $Active,             "\n";
print "PassArguments = ",      $PassArguments,      "\n";
print "OwnSection = ",         $OwnSection,         "\n";
print "OwnUnit = ",            $OwnUnit,            "\n";
print "Executable = ",         $Executable,         "\n";
print "ExecutableType = ",     $ExecutableType,     "\n";
for ($j=0; $j<$stringcount; $j++) {print "$strings[$j]\n"}

=ScheduleLANHeader
                      offset  length   total
            variable dec hex dec hex dec hex type
-------------------------------------------------
        LastScanTime 000 000 008 008 008 008 date
     NextExecuteTime 008 008 008 008 016 010 date
  NextExecuteTimeSet 016 010 002 002 018 012 int
        MinutesToRun 018 012 004 004 022 016 long
              TaskID 022 016 008 008 030 01E double
                  ID 030 01E 004 004 034 022 string
       ProcScheduler 034 022 001 001 035 023 string
            ProcName 035 023 030 01E 065 041 string
              Active 065 041 002 002 067 043 int
       PassArguments 067 043 002 002 069 045 string
          OwnSection 069 045 004 004 073 049 string
             OwnUnit 073 049 004 004 077 04D string
          Executable 077 04D 256 100 333 14D string
      ExecutableType 333 14D 002 002 335 14F int
          TextOffset 335 14F 488 1E8 823 337 long array 61x2d

>From: David McDivitt <x12code-del@del-yahoo.com>
>Date: Fri, 05 Sep 2003 17:09:20 -0500
>Lines: 40
>
>I am experienced with VB and just starting to learn Perl. It's necessary for
>me to read files written by VB and display from a CGI script. Changing the
>VB app is not an option, so I need to get Perl to interpret VB data types
>when read from the file.
>
>This is the VB user defined type:
>
>Public Const StatusMaxAppPointer = 57
>Public Const StatusCommonPointer = 58
>Public Const StatusResourcePointer = 59
>Public Const StatusOnCallPointer = 60
>'
>Public Type ProcRec
>    LastScanTime As Date
>    NextExecuteTime As Date
>    NextExecuteTimeSet As Integer
>    MinutesToRun As Long
>    TaskID As Double
>    ID As String * 4
>    ProcScheduler As String * 1
>    ProcName As String * 30
>    Active As Integer
>    PassArguments As Integer
>    OwnSection As String * 4
>    OwnUnit As String * 4
>    Executable As String * 256
>    ExecutableType As Integer
>    TextOffset(StatusOnCallPointer, 1) As Long
>    End Type
>
>This user defined type exists as a header at the front of a binary file.
>TextOffset contains pointers and lengths of strings comprising the remainder
>of the file. In VB the file is opened, the header read, and a sixty element
>string array is populated using values from TextOffset in the header.
>
>I thought about writing a VB program which would read the file and write
>back out as text, but I would have to have some type of piping between Perl
>and the VB program. I would prefer to read and interpret with Perl. Any
>thoughts would be appreciated.



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

Date: Sun, 07 Sep 2003 02:49:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: read VB file with Perl
Message-Id: <3F5A9CAE.F3D26AA2@acm.org>

David McDivitt wrote:
> 
> Thanks to Vlad Tepes for getting me going on this. My Perl program is
> below. Neat thing is Perl unpacks double floating point values straight
> out of the input buffer. The date data type in VB is a double with days
> to the left of the decimal and time to the right. Anyone know how to
> convert double values to a date string?

Multiply the date by the number of seconds in a day and use localtime to
convert that to a date string.


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 06 Sep 2003 23:05:29 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: splitting an array
Message-Id: <3f5a6829.346432782@news.erols.com>

tiltonj@erols.com (Jay Tilton) wrote:

: debhatta@hotmail.com (debraj) wrote:
: 
: : I have one array of numbers say (12 17 18 19 120 121 122 123 124 379
: : 480 481).
: : Now I want to get the starting and ending of any cosecutive numbers
: : from this array .
: : For eg. result should be (12--12,17--19,120--124,379--379,480--481) .
: : Note that  if a number without any sequence is present it will be
: : printed in the format 12--12 .
: 
:     my @ary = (12,17,18,19,120,121,122,123,124,379,480,481);
:     my $seqs = join ',', map "$_--$_", sort {$a <=> $b} @ary;
:     1 while $seqs  =~ s/(\d+),(??{$1+1})--(\d+)/$2/;
:     print "($seqs)\n";

Or, using an actual data structure instead of a string,

    my @ary = (12,17,18,19,120,121,122,123,124,379,480,481);
    my @seqs = map [$_, $_], sort {$a <=> $b} @ary;
    $seqs[$_-1][1] = (splice @seqs, $_, 1)[0]->[1]
        for grep $seqs[$_-1][1] == $seqs[$_][0]-1 => reverse 1..$#seqs;
    print join ',' => map sprintf('%d--%d', @$_), @seqs;

Kinda fun.  I remember seeing variations on this problem solved before on
clpm, but I couldn't hit on the right Google Groups search terms.  Any
pointers?



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

Date: Sat, 06 Sep 2003 20:06:35 -0400
From: LaDainian Tomlinson <go@away.spam>
Subject: Re: splitting an array
Message-Id: <pan.2003.09.06.20.06.35.375264.1359@away.spam>

On Sat, 06 Sep 2003 03:18:25 -0400, debraj wrote:
> I have one array of numbers say (12 17 18 19 120 121 122 123 124 379 480
> 481).
> Now I want to get the starting and ending of any cosecutive numbers from
> this array .
> For eg. result should be (12--12,17--19,120--124,379--379,480--481) .
> Note that  if a number without any sequence is present it will be
> printed in the format 12--12 .

This may not help much, but it works for your case and I learned a lot :-)


_(qw.12 17 18 19 120 121 122 123 124 379 480 481.);
sub _{
  print($_ = shift);
  while(@_){ ($_[0] == $_ + 1) ? $_ = shift : last; }
  print("--$_\n"), (@_ && _(@_));
}


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

Date: Sat, 6 Sep 2003 20:42:21 +0000 (UTC)
From: J Krugman <jill_krugman@yahoo.com>
Subject: Strange behavior after reading big file
Message-Id: <bjdgrd$kq9$1@reader2.panix.com>




I have a piece of code that looks something like this:

  my %hash;
  my $i = 0;
  open HUGE, 'Huge_File' or die '>*choke*<';
  $| = 1; print "\n";
  for my $x (<HUGE>) {
    chomp $x;
    $hash{$x} = $i++ if some_test($x);
    print "\rProcessed up to line $i   " unless $i % 10000;
  }
  close HUGE;
  print "Done reading Huge_File\n";

  # ... do something with %hash

When I run this code, it dutifully reports processing the total
number of lines (to the nearest 10000), but it never prints "Done
reading ... ".  As far as I can tell it just hangs.  The code works
fine if the input file is of a "normal" size (1000 lines, say),
but I need to run it on a file that is 25 million lines long, and
it is in this case that I observe the hanging behavior I've just
described.

Any suggestions would be most welcome.  FWIW the OS is Linux, and
I'm running Perl 5.6.1, and have 0.5G of RAM.

Thanks!

	-Jill

Huge_File has about 25 million lines.  The reporter statement 



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

Date: Sat, 6 Sep 2003 17:11:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Strange behavior after reading big file
Message-Id: <slrnblkmrq.76h.tadmc@magna.augustmail.com>

J Krugman <jill_krugman@yahoo.com> wrote:

>   for my $x (<HUGE>) {


> but I need to run it on a file that is 25 million lines long,


Then don't read the entire thing into memory:

   while ( my $x = <HUGE> ) {


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 6 Sep 2003 23:28:31 +0000 (UTC)
From: J Krugman <jill_krugman@yahoo.com>
Subject: Re: Strange behavior after reading big file
Message-Id: <bjdqiv$n91$1@reader2.panix.com>

In <slrnblkmrq.76h.tadmc@magna.augustmail.com> tadmc@augustmail.com (Tad McClellan) writes:

>J Krugman <jill_krugman@yahoo.com> wrote:

>>   for my $x (<HUGE>) {


>> but I need to run it on a file that is 25 million lines long,


>Then don't read the entire thing into memory:

>   while ( my $x = <HUGE> ) {

Yikes.  What a whopper.

Thank you so much!

	-Jill


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

Date: Sat, 6 Sep 2003 22:45:06 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: View NG with Net::NNTP
Message-Id: <bjdo1i$phq$1@geraldo.cc.utexas.edu>



  csdude@hotmail.com (Mike) wrote:
 ..........
 >So far, I've researched LWP::UserAgent and Net::NNTP. Both seem like
>they're talking about viewing and posting, but all of the references
>I'm finding are about posting. Can either of these let me view the
>articles themselves? I don't think I'll have a problem with posting,
>just viewing.
 .......

 Mike,
 Your question has probably been well answered, but here is some code I once
used as part of a webnews reader I wrote; you might be able to use/alter it:

The following gets headers (with Subject displayed):
(Usage example: headers clpm 10)

#!/usr/bin/perl

use Net::NNTP;

my $nntp = Net::NNTP->new() or die "Couldn't connect: $!\n";
$group=shift;
if($group eq "rgp"){$group="rec.gambling.poker"}
if($group eq "clpm"){$group="comp.lang.perl.misc"}
$number=shift;
@group=$nntp->group($group);
($first,$last)=@group[1,2];
$header_hashref=$nntp->xhdr("Subject",[$last-$number+1,$last]);
@keys=sort{$a<=>$b}(keys %$header_hashref);
for $x(@keys){
print "Msg $x ";
print "Subject: $$header_hashref{$x}\n";
}
$nntp->quit;

The following gets an article:
(Usage example: get clpm 496687)

#!/usr/bin/perl

use Net::NNTP;

my $nntp = Net::NNTP->new() or die "Couldn't connect: $!\n";
$group=shift;
if($group eq "rgp"){$group="rec.gambling.poker"}
if($group eq "clpm"){$group="comp.lang.perl.misc"}
$number=shift;
@group=$nntp->group($group);
$article=$nntp->article($number);
print "@$article\n";
$nntp->quit;

There may be better ways of doing these things, but the above
worked well for me. You can also easily display other parts of the
header. The book "Network Programming with Perl" by L. Stein, Addison Wesley
has a lot of great information and examples.

chas
--
for((112,97,99,107)){$s.=chr $_};
($z="``'=``:=`~,=``~=``{=;'=``'=+}=++=`~}=;".
"'=;+=++=:'=;+=::=:~=,,=,'=::=,'=,:=::=,:=,;".
"=::=,'=,:=::=,{=:_=::=,'=,:=::=,,=,~=::=,'=,".
":=::=:+=:_=:`=,+=`~")=~tr/~`';:,{}_+=/0-9i/; 
eval "\$_=$s 'c*', qw/@{[split /i/,$z]}/;";print;







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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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 5454
***************************************


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