[28839] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 83 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 28 09:06:33 2007

Date: Sun, 28 Jan 2007 06:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 28 Jan 2007     Volume: 11 Number: 83

Today's topics:
    Re: adding floating point <perl4hire@softouch.on.ca>
    Re: adding floating point <abigail@abigail.be>
    Re: adding floating point <perl4hire@softouch.on.ca>
    Re: custom regexp modifiers <paul@probulletin.com>
    Re: custom regexp modifiers <bik.mido@tiscalinet.it>
        new CPAN modules on Sun Jan 28 2007 (Randal Schwartz)
    Re: Removing HTML <joe@inwap.com>
        Seperating Perl code and HTML using Here Documents... barrybevel@ananzi.co.za
    Re: Seperating Perl code and HTML using Here Documents. <spamtrap@dot-app.org>
    Re: Seperating Perl code and HTML using Here Documents. <uri@stemsystems.com>
    Re: Seperating Perl code and HTML using Here Documents. barrybevel@ananzi.co.za
    Re: Seperating Perl code and HTML using Here Documents. <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Seperating Perl code and HTML using Here Documents. <bik.mido@tiscalinet.it>
    Re: Undefined subroutine even though it appears in symb <namedcoward@gmx.ch>
    Re: Undefined subroutine even though it appears in symb <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 27 Jan 2007 14:14:42 -0500
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: adding floating point
Message-Id: <nvNuh.3364$WL2.1287@read1.cgocable.net>

Jürgen Exner wrote:
> Amer Neely wrote:
>>> FAQ 'Why am I getting long decimals (eg, 19.9499999999999) ## instead of 
>>> the numbers I should be getting (eg, 19.95)?' and other
>> OK, this is making more sense now. I was confusing the 'display' value
>> with the underlying real one (no pun intended). I've managed to get it
>> working by applying a rounding operation to each value along the way.
> 
> That is not a good idea. You are replacing one place of introducing 
> inaccuracy with numerous places of introducing inaccuracy.
> 
> There are two options:
> - Live with 'real' numbers being inaccurate
> - use a different representation for your values, e.g. compute your prices 
> in pennies instead of in dollars. And convert them to dollar for display 
> only. Natural numbers can be represented accurately without approximation.
> 
> jue 
> 
> 

I understand what you are saying, but I don't think this application 
requires the degree of accuracy you are considering. I only need to 
reflect what someone with a calculator, or using their head, would 
arrive at, applying standard rounding.

Now, if this were a financial investment application, I wouldn't even 
consider doing it myself.

-- 
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"


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

Date: 27 Jan 2007 23:38:28 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: adding floating point
Message-Id: <slrnernojd.tcf.abigail@alexandra.abigail.be>

Amer Neely (perl4hire@softouch.on.ca) wrote on MMMMDCCCXCVII September
MCMXCIII in <URL:news:5HKuh.18184$Ah.7894@read2.cgocable.net>:
~~  
~~  OK, this is making more sense now. I was confusing the 'display' value 
~~  with the underlying real one (no pun intended). I've managed to get it 
~~  working by applying a rounding operation to each value along the way. 
~~  But if I understand, printf (or sprintf) to each value would achieve the 
~~  same? I'll try that next. Thanks :)


No, I think you're making a mistake. Using a variable as argument to
printf (or sprintf) doesn't change the value of that variable. printf
prints a *different* value (2.42 instead of 2.415 in this case). 



Abigail
-- 
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
 |perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
 |perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
 |perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;


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

Date: Sun, 28 Jan 2007 00:46:04 -0500
From: Amer Neely <perl4hire@softouch.on.ca>
Subject: Re: adding floating point
Message-Id: <hLWuh.18244$Ah.13571@read2.cgocable.net>

Abigail wrote:
> Amer Neely (perl4hire@softouch.on.ca) wrote on MMMMDCCCXCVII September
> MCMXCIII in <URL:news:5HKuh.18184$Ah.7894@read2.cgocable.net>:
> ~~  
> ~~  OK, this is making more sense now. I was confusing the 'display' value 
> ~~  with the underlying real one (no pun intended). I've managed to get it 
> ~~  working by applying a rounding operation to each value along the way. 
> ~~  But if I understand, printf (or sprintf) to each value would achieve the 
> ~~  same? I'll try that next. Thanks :)
> 
> 
> No, I think you're making a mistake. Using a variable as argument to
> printf (or sprintf) doesn't change the value of that variable. printf
> prints a *different* value (2.42 instead of 2.415 in this case). 
> 
> 
> 
> Abigail

Yes, which is what I would expect from a rounding function.

I've used some of the suggestions and am now getting a 'more' correct 
answer. 2.42 is what I would expect to see on an invoice, not 2.415, 
even though that is the mathematically correct value. But in most 
day-to-day financial transactions, we round up or down, and this is the 
'right' answer as far as I can see - the addition is now correct.

#! /usr/bin/perl

BEGIN
{
	open (STDERR,">>$0-err.txt");
	print STDERR "\n",scalar localtime,"\n$0\n";
}

use strict;
use warnings;
unless ($#ARGV == 1)
{
   print "Usage: calc subtotal shipping\n";
   exit;
}
my $subtotal=$ARGV[0];
my $shipping=$ARGV[1];
my $fuelfee=($shipping / 10);
printf "%8.2f\n",$subtotal;
printf "%8.2f\n",$shipping;
printf "%8.2f\n",$fuelfee;
my $newtotal=round( $subtotal + $shipping + ($shipping / 10) ,2);
print "=" x 8,"\n";
## from Abigail
printf qq{%8.2f} => sprintf (qq{%8.2f} => 24.25 / 10) + 24.15 + 185.63;

sub round
{
   my ($n, $p) = @_;
   $p ||= 0;
   int($n * 10**$p + .5 * ($n < 0 ? -1 : 1)) / 10**$p;
}


-- 
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"


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

Date: 27 Jan 2007 14:46:06 -0800
From: "Paul" <paul@probulletin.com>
Subject: Re: custom regexp modifiers
Message-Id: <1169937966.919623.222290@s48g2000cws.googlegroups.com>

Correct, it shouldn't be there. Just a lack of concentration.



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

Date: Sat, 27 Jan 2007 23:53:42 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: custom regexp modifiers
Message-Id: <6ulnr218qjn3c9csae880jcds60486kklv@4ax.com>

On 27 Jan 2007 14:46:06 -0800, "Paul" <paul@probulletin.com> wrote:

>Correct, it shouldn't be there. Just a lack of concentration.

What? Please quote *some* relevant context from the post you reply to,
for maximum clarity...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 28 Jan 2007 05:42:09 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Jan 28 2007
Message-Id: <JCKD69.Gu4@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Apache-SWIT-0.21
http://search.cpan.org/~bosu/Apache-SWIT-0.21/
mod_perl based application server with integrated testing.
----
Archive-Tar-Wrapper-0.08
http://search.cpan.org/~mschilli/Archive-Tar-Wrapper-0.08/
API wrapper around the 'tar' utility
----
CPAN-1.88_71
http://search.cpan.org/~andk/CPAN-1.88_71/
query, download and build perl modules from CPAN sites
----
DBIx-SQLite-Simple-0.34
http://search.cpan.org/~gomor/DBIx-SQLite-Simple-0.34/
easy access to SQLite databases using objects
----
DJabberd-Plugin-Ping-0.45
http://search.cpan.org/~misc/DJabberd-Plugin-Ping-0.45/
Add support for "XEP 0199, Xmpp Ping" to DJabberd.
----
Getopt-Long-2.36
http://search.cpan.org/~jv/Getopt-Long-2.36/
Extended processing of command line options
----
HTML-Tested-0.22
http://search.cpan.org/~bosu/HTML-Tested-0.22/
Provides HTML widgets with the built-in means of testing.
----
HTML-Tested-ClassDBI-0.09
http://search.cpan.org/~bosu/HTML-Tested-ClassDBI-0.09/
Enhances HTML::Tested to work with Class::DBI
----
LaTeX-Pod-0.09_01
http://search.cpan.org/~schubiger/LaTeX-Pod-0.09_01/
Transform LaTeX source files to POD (Plain old documentation)
----
Math-BigInt-Random-0.02
http://search.cpan.org/~billh/Math-BigInt-Random-0.02/
arbitrary sized random integers
----
Palm-KeyRing-0.01
http://search.cpan.org/~jv/Palm-KeyRing-0.01/
Interface to GNU KeyRing databases
----
TeX-Encode-0.9
http://search.cpan.org/~timbrody/TeX-Encode-0.9/
Encode/decode Perl utf-8 strings into TeX
----
Win32-Process-List-0.05
http://search.cpan.org/~rpagitsch/Win32-Process-List-0.05/
Perl extension to get all processes and thier PID on a Win32 system
----
version-0.69_01
http://search.cpan.org/~jpeacock/version-0.69_01/
Perl extension for Version Objects


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
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: Sat, 27 Jan 2007 15:23:53 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Removing HTML
Message-Id: <BbydnSRBOPmUQibYnZ2dnUVZ_tLinZ2d@comcast.com>

Bill H wrote:
> Does anyone have an easy/fast way of removing HTML tags from a text
> file using perl? 

Once upon a time someone complained that HTML::Parser was too hard to use.
I whipped up this little ditty to show it's easy.
	-Joe


#!/usr/bin/perl
# Name: nohtml                  Author: Joe.Smith@inwap.com 07-Nov-2001
# Purpose: Extracts just the text portions of a document.

use strict; use warnings;
use HTML::Parser ();

sub text_handler {            # Ordinary text
     print @_;
}

my $p = HTML::Parser->new(api_version => 3);
$p->handler( text => \&text_handler, "dtext");
$p->parse_file(shift || "-") || die $!;


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

Date: 27 Jan 2007 21:26:02 -0800
From: barrybevel@ananzi.co.za
Subject: Seperating Perl code and HTML using Here Documents...
Message-Id: <1169961962.789259.240370@p10g2000cwp.googlegroups.com>

Hi,
 I have a Perl cgi program which can return a number of different HTML 
pages based on input.
I am using Here Documents to hold the HTML pages with $variables to 
output dynamic content.
The way I'm doing it is becoming very sloppy and unmanageable.

Can someone suggest a better/cleaner way of seperating dynamic HTML 
and perl code?

Here's an example of what I'm doing (shame on me):

my $webpage;
my $var1;
my $var2;
 ...
if( ...) {
 open (FILE, 'good-page.pl') or die "blah...";
 my @code = <FILE>;
 eval join("\n", @code);

} else {
 open (FILE, 'bad-page.pl') or die "blah...";
 my @code = <FILE>;
 eval join("\n", @code);
}
 ...
print "http headers...";
print $webpage;

############################################

# good-page.pl

$webpage = <<PAGE;
<html>
 ...
Good Page $var1
 ...
</html>
PAGE

############################################

# bad-page.pl

$webpage = <<PAGE;
<html>
 ...
Bad Page $var2
 ...
</html>
PAGE



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

Date: Sun, 28 Jan 2007 00:34:26 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Seperating Perl code and HTML using Here Documents...
Message-Id: <m2tzybsoil.fsf@Sherm-Pendleys-Computer.local>

barrybevel@ananzi.co.za writes:

> Can someone suggest a better/cleaner way of seperating dynamic HTML 
> and perl code?

Have a look at the Template::Toolkit or HTML::Mason modules on CPAN.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sun, 28 Jan 2007 00:48:30 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Seperating Perl code and HTML using Here Documents...
Message-Id: <x73b5vwvkh.fsf@mail.sysarch.com>

>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:

  SP> barrybevel@ananzi.co.za writes:
  >> Can someone suggest a better/cleaner way of seperating dynamic HTML 
  >> and perl code?

  SP> Have a look at the Template::Toolkit or HTML::Mason modules on CPAN.

or even Template::Simple which is much easier to learn and use.  call it
david vs goliath of template modules.  4 markups and 150 lines of module
code vs massive code and docs to learn.  :)

but i do agree templating is the way to go instead of numerous here
docs.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 27 Jan 2007 22:09:32 -0800
From: barrybevel@ananzi.co.za
Subject: Re: Seperating Perl code and HTML using Here Documents...
Message-Id: <1169964572.158168.306380@j27g2000cwj.googlegroups.com>

Thanks Sherm & Uri, very quick response.

I'll have a look at:

Template::Simple
Template::Toolkit
HTML::Mason

Regards...

On Jan 28, 6:48 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "SP" == Sherm Pendley <spamt...@dot-app.org> writes:  SP> barrybe...@ananzi.co.za writes:
>   >> Can someone suggest a better/cleaner way of seperating dynamic HTML
>   >> and perl code?
>
>   SP> Have a look at the Template::Toolkit or HTML::Mason modules on CPAN.
>
> or even Template::Simple which is much easier to learn and use.  call it
> david vs goliath of template modules.  4 markups and 150 lines of module
> code vs massive code and docs to learn.  :)
>
> but i do agree templating is the way to go instead of numerous here
> docs.
>
> uri
>
> --
> Uri Guttman  ------  u...@stemsystems.com  --------http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org



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

Date: Sun, 28 Jan 2007 09:55:50 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Seperating Perl code and HTML using Here Documents...
Message-Id: <45bc6517$0$27383$ba4acef3@news.orange.fr>

barrybevel@ananzi.co.za wrote:
> Thanks Sherm & Uri, very quick response.
> 
> I'll have a look at:
> 
> Template::Simple
> Template::Toolkit
> HTML::Mason
> 

HTML::Template may also fit the bill.

Mark


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

Date: Sun, 28 Jan 2007 12:48:07 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Seperating Perl code and HTML using Here Documents...
Message-Id: <8quor2hrmtc4v85qq2120co5jo6t308dk9@4ax.com>

On 27 Jan 2007 21:26:02 -0800, barrybevel@ananzi.co.za wrote:

>Can someone suggest a better/cleaner way of seperating dynamic HTML 
>and perl code?

Others already suggested you to try and choose one out of the ton
templating modules out there. Indeed that *is* a better way for
"seperating dynamic HTML and perl code". However I'll add some
comments to your actual code.

>my $webpage;
>my $var1;
>my $var2;
>...
>if( ...) {
> open (FILE, 'good-page.pl') or die "blah...";
> my @code = <FILE>;
> eval join("\n", @code);

Basically you're reinventing Perl's do() function, and in a clumsy way
too. At the very least you should know that you can slurp in files all
at once into a scalar, either local()ly setting $/ to undef or with
File::Slurp. Thus the above may be

  eval do {
      open my $fh, 'good-page.pl' or die "D'Oh! $!\n";
      local $/;
      scalar <$fh>;
  };

See? No unnecessary join()... but then, as I wrote above, it may also
be just as simple as

  do 'good-page.pl';

>print "http headers...";

BTW: I know this is pseudocode, but just to be sure: it is *always*
recommended and for -trust me- very good reasons, not to reinvent the
wheel with the risk of doing so in possibly erroneous ways, but to use
CGI.pm instead.

>print $webpage;
>
>############################################
>
># good-page.pl
>
>$webpage = <<PAGE;
><html>
>...
>Good Page $var1
>...
></html>
>PAGE

So these external Perl scripts only "load" a page into a scalar. One
may wonder why you don't get rid of the Perl code and directly load
the HTML pages. Of course the answer is that you interpolare $var1,
$var2, etc. This is where one sees the usefulness of a templating
system. If things are really this simple, you may roll your own
templating system though, so you may have a file like:

  <html>
  ...
  Good Page [var1]
  ...
  </html>

called good-page.tpl, and in your Perl script you would do something
like

  my %config=( var1 => 'foo',
               var2 => 'bar' );
  my $default='baz';
  
  my $webpage;
  if( whatever() ) {
      $webpage=load('good-page.tpl');
  } else {
      $webpage=load('bad-page.tpl');
  }
  $webpage =~ s/\[(\w+?)\]/$config{$1}||$default/ge;
  
  sub load {
      my $file=shift;
      open my $fh, '<', $file
        or die "Can't open `$file': $!\n";
      local $/;
      scalar <$fh>;
  }

Of course, the more you need to add features, the more you will create
yet another full fledged templating system, with all the difficulties
of doing so, so you will realize that maybe it would have been better
to choose a ready made one in the first place. It all really depends
on how complex your requirements actually are.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 27 Jan 2007 12:06:15 -0800
From: "max.gruber" <namedcoward@gmx.ch>
Subject: Re: Undefined subroutine even though it appears in symbol table?
Message-Id: <1169928375.403162.101910@k78g2000cwa.googlegroups.com>

Unfortunately, I've been unable to reproduce it outside of the program 
where it occurs. And that would be much too large to post.

Anyways, how would you go about debugging a run-time undefined 
subroutine error? What could possibly cause it?



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

Date: 27 Jan 2007 14:11:20 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Undefined subroutine even though it appears in symbol table?
Message-Id: <1169935880.842700.318700@q2g2000cwa.googlegroups.com>

On Jan 27, 3:06 pm, "max.gruber" <namedcow...@gmx.ch> wrote:
> Unfortunately, I've been unable to reproduce it outside of the program
> where it occurs. And that would be much too large to post.

This is non sensical.  Take your existing program.  Remove everything 
not directly related to the bug.  Post what's left.

> Anyways, how would you go about debugging a run-time undefined
> subroutine error? What could possibly cause it?

Programmer error.

Paul Lalli



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 83
*************************************


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