[9494] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3089 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 8 00:07:29 1998

Date: Tue, 7 Jul 98 21:01:33 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Jul 1998     Volume: 8 Number: 3089

Today's topics:
    Re: NEVER "call warn() and return undef" (Re: question  (Mark-Jason Dominus)
    Re: new charter and moderator for comp.lang.perl.announ <pgunn01@ibm.net>
        New mind to mold. <crash323@jps.net>
    Re: Oh man, DO I love Perl ! (References to things that (Ronald J Kimball)
        Order form script question <BillMonti@yahoo.com>
    Re: Order form script question (brian d foy)
    Re: Order form script question <s027119@income.com.sg>
    Re: Order form script question (Mark-Jason Dominus)
    Re: Order form script question <steph@hotkey.net.au>
    Re: Order form script question (Martien Verbruggen)
    Re: Pattern matching problems (Larry Rosler)
    Re: Pattern matching problems (Ronald J Kimball)
        Problem in Variable String to Open() <ernestm@towery.com>
    Re: Problem in Variable String to Open() (brian d foy)
    Re: Problem in Variable String to Open() (Martien Verbruggen)
        Proper locking of DBM files? (Jxrn-Morten Innselset)
    Re: question about objects (Mark-Jason Dominus)
    Re: question about objects <tchrist@mox.perl.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Jul 1998 21:37:34 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: NEVER "call warn() and return undef" (Re: question about objects)
Message-Id: <6nuigu$iaa$1@monet.op.net>


John Porter <jdporter@min.net> wrote:
> : Here's a tip: if your constructor won't returned a properly blessed
> : reference, have it call warn, and return undef.

Zenin wrote:
>         Ack!  No!  DO **NOT** DO THIS!


In article <35A0D109.7459@min.net>, John Porter  <jdporter@min.net> wrote:
>Whatever.

I'm with Zenin on this one.  If I invoke a function in a module, the
last thing I want it to do is to go burping random messages to
standard error.

I like the `Set $module::ERROR and return undef' approach much better.
Once you issue a warning with `warn', it's gone and can't be gotten back.

>The essential point I was trying to make was that the function should
>return undef, not some string containing an error message.
>If it chooses to do something else with that message, fine.

I agree with your essential point.  But it's important to put the
message somewhere that the program can get to it.  Printing it out to
standard error is not such a place.  Errors should be propogated back
up the call stack until they can be handled.  Whether to inform the
user or not is a high-level decision and shouldn't be usurped by a
module.



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

Date: Tue, 07 Jul 1998 21:55:50 -0400
From: Pat Gunn <pgunn01@ibm.net>
Subject: Re: new charter and moderator for comp.lang.perl.announce
Message-Id: <35A2D1A6.53BC@ibm.net>

Daniel Grisinger wrote:
> 
> [posted and mailed to the cited author]
> In article <8c4swtjndm.fsf@gadget.cscaper.com>
> Randal Schwartz <merlyn@stonehenge.com> wrote:
> 
> >In discussions over the past few weeks, most people agree that
> >allowing some degree of commercial advertising would be nice.  The
> 
> Hmmmmm.... what degree?  I'd personally like to see no commercial
> announcements on clpa, but I do see where some things (conferences,
> journals (if more appear), etc.) could reasonably be announced
> there.
> 
> >So, what do you think a new charter should permit/deny?
> 
> I think it should allow for announcements of new perl releases,
> new modules, books, conferences, and magazines.  Commercial products
> that are meant to be used by perl programmers for programming perl
> may also be on-topic, but I don't want to wade through hundreds
> of ads for `Joe-Bob's New and Improved WWW Shopping Cart!!' just
> because it happens to C<use CGI;>.
> 
> >                                                         Who do you
> >think should be moderator?
> 
> Volunteers?

I would like to nominate myself as moderator for comp.lang.perl.misc.
I have no real preconceptions about how the group should be
run, and would stand by whatever the consensus reached by this
discussion
ends up being. I have moderation experience, having comoderated 
comp.os.os2.moderated since it's conception and having moderated
comp.sys.newton.announce for awhile now. If a consensus were not
reached by discussion in this group, I'd probably go with:

Announcements that would be of interest to users of perl, including
info about new modules, books, conferences, magazines, user's group
info, contests, etc., but not including mundane uses of perl, such
as Joe Random announcing that he has a website that uses a Perl script.

As I said, if the majority of the people think differently than me
on the issue as evidenced by discussion on this ng, I'd go their way.

-- 
---------------------------------------------------
Pat Gunn, moderator:comp.sys.newton.announce
comoderator:comp.os.os2.moderated
"You can always judge a man by the quality of his enemies." -- Dr Who
http://junior.apk.net/~qc
------------------------------------------------


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

Date: Tue, 7 Jul 1998 20:41:14 -0700
From: "n/a" <crash323@jps.net>
Subject: New mind to mold.
Message-Id: <35a2ea80.0@blushng.jps.net>

Hello,
    A few weeks ago, I learned that my ISP gives me a shell account to a BSD
machine. After the elation died down I set my mind to learning the system,
and soon after Perl. I have understood for a while that the Internet's
backbone is UNIX and to truly be an Internet-wise person I had to harness
it's power. So I tried my hand at the "Hello World" program which I had
already done with BASIC and C (which I soon dropped, but am eager to learn.)
and then looked for the on-line tutorials. After getting a _very_ basic
knowledge of Scalars, Arrays, and so on, I realized I need a more detailed
source of Perl wisdom to refer to. I have read about The Camel and Lama
books, but it was soon brought to my attention that these were more of the
Perl-inclined. So my basic question is this: where (online or printed
literature) can I find tutorials and related information about Perl for a
non-expert?

Thank you so much,
Comron.
Someone who _wants_ to be "Just Another Perl Hacker." - hope that was the
right thing to say.




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

Date: Tue, 7 Jul 1998 23:27:13 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Oh man, DO I love Perl ! (References to things that go out of scope)
Message-Id: <1dbtjrr.1pjo97tt3yjcgN@bay2-137.quincy.ziplink.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:

> In comp.lang.perl.misc, 
>     Randal Schwartz <merlyn@stonehenge.com> writes:
> :And except for that last phrase, that's exactly what we did. :-)
> 
> For peculiar values of "we".

Tom probably considers any value of "we" other than "the Royal we" as
peculiar.  ;-)

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 08 Jul 1998 02:25:58 GMT
From: "Bill Monti" <BillMonti@yahoo.com>
Subject: Order form script question
Message-Id: <WMAo1.188$I_.514880@news.sgi.net>

I am a lowly (!) college student trying to do a friend a favor by making his
web site.  Part of this site involves a product order form.  I have written
a script to accept the values given in the order form itself and creates
the extended price, tax, shipping charges and a total in a dynamically
created page that then gets the customer's personal info.  My problem is
(simple, I'm sure, but I am sick of looking for an answer!) that I cannot
get the dynamically created values to be in a currency-type format
(truncated to or forced to be to two decimal places).

Could someone please enlighten me to how this is done?  I have searched a
ton of FAQ pages and have not come across this subject.

Thanks for your help.




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

Date: Tue, 07 Jul 1998 23:02:55 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Order form script question
Message-Id: <comdog-ya02408000R0707982302550001@news.panix.com>
Keywords: from just another new york perl hacker

In article <WMAo1.188$I_.514880@news.sgi.net>, "Bill Monti" <BillMonti@yahoo.com> posted:

>created page that then gets the customer's personal info.  My problem is
>(simple, I'm sure, but I am sick of looking for an answer!) that I cannot
>get the dynamically created values to be in a currency-type format
>(truncated to or forced to be to two decimal places).


just know where to start looking!

[NB:  `man` works equally as well]

%perldoc perlfaq

[snip]
     the perlfaq1 manpage: General Questions About Perl
          Very general, high-level information about Perl.
[snip]

%perldoc perlfaq4

[snip]
     Why am I getting long decimals (eg, 19.9499999999999)
     instead of the numbers I should be getting (eg, 19.95)?
[snip]


good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: 8 Jul 1998 03:07:27 GMT
From: "S. Sarkar" <s027119@income.com.sg>
Subject: Re: Order form script question
Message-Id: <01bdaa1d$46dffda0$2d1809a8@sarkar.income.com.sg>

use the following :
$currency=23.989089;
$currency=sprintf("%.2f",$currency);
print $currency;
should print : 23.99

thanx

Bill Monti <BillMonti@yahoo.com> wrote in article
<WMAo1.188$I_.514880@news.sgi.net>...
> I am a lowly (!) college student trying to do a friend a favor by making
his
> web site.  Part of this site involves a product order form.  I have
written
> a script to accept the values given in the order form itself and creates
> the extended price, tax, shipping charges and a total in a dynamically
> created page that then gets the customer's personal info.  My problem is
> (simple, I'm sure, but I am sick of looking for an answer!) that I cannot
> get the dynamically created values to be in a currency-type format
> (truncated to or forced to be to two decimal places).
> 
> Could someone please enlighten me to how this is done?  I have searched a
> ton of FAQ pages and have not come across this subject.
> 
> Thanks for your help.
> 
> 
> 


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

Date: 7 Jul 1998 23:08:11 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Order form script question
Message-Id: <6nunqr$j2q$1@monet.op.net>


In article <WMAo1.188$I_.514880@news.sgi.net>,
Bill Monti <BillMonti@yahoo.com> wrote:
>I cannot get the dynamically created values to be in a currency-type format
>(truncated to or forced to be to two decimal places).

Maybe you want

	$amount = 20/3;
	$dollars = sprintf('$%.2f', $amount);
	print $dollars, "\n"

==>		$6.67		




A better `Subject' for your post would have been `How to round to two
decimal places?'


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

Date: Wed, 08 Jul 1998 13:14:27 +1000
From: Stephan Carydakis <steph@hotkey.net.au>
Subject: Re: Order form script question
Message-Id: <35A2E413.3DE8@hotkey.net.au>

Bill Monti wrote:
> 
> (truncated to or forced to be to two decimal places).
> 
> Could someone please enlighten me to how this is done?  I have searched a
> ton of FAQ pages and have not come across this subject.
> 
> Thanks for your help.

Hi Bill,

I am a newbie to perl(so dont take this answer as gospel), but I think
sprintf will work for you. Something like:

       $formatted_variable = sprintf "%.2f","$unformatted_vatiable";


Should work (I think), but I'm sure that if it is wrong, someone will
point this out.

Hope this helps you :]

Regards,
___________________________________________________
Stephan Carydakis     steph@hotkey.net.au
___________________________________________________


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

Date: 8 Jul 1998 03:18:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Order form script question
Message-Id: <6nuof1$oii$6@comdyn.comdyn.com.au>

In article <WMAo1.188$I_.514880@news.sgi.net>,
	"Bill Monti" <BillMonti@yahoo.com> writes:

[snip irrelevant stuff]

> that I cannot get the dynamically created values to be in a currency-type
> format (truncated to or forced to be to two decimal places).

This actually rounds, but I guess that's even better, not?

my $gold = 1234.5678;
my $money = sprintf "\$%.2f", $gold;
print "$gold -> $money\n";

> Could someone please enlighten me to how this is done?  I have searched a
> ton of FAQ pages and have not come across this subject.

# perldoc perlfaq5
/Does perl have a round function?

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: Tue, 7 Jul 1998 18:33:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Pattern matching problems
Message-Id: <MPG.100c6c2f18931e899896f2@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <35A2C2A7.8E6C3763@shaw.wave.ca> on Wed, 08 Jul 1998 01:44:40 
GMT, Rick Delaney <rick.delaney@shaw.wave.ca> says...
> Ross Mullen wrote:
> > 
> > The second also involves pattern matching, it again reads an input and
> > any vowels encountered changes them to another vowel and prints out 
> > the first change the (whole word with the first character changed) 
> > then the second change in the whole word and so on. 
> 
> This should do what you want.  I can't think offhand how to do this
> using s///.
> 
> #!/usr/local/bin/perl
> use strict;
> 
> my %newvowel = (
>  a => 'o',
>  e => 'a',
>  i => 'u',
>  o => 'i',
>  u => 'e',
> );
> my $newword = my $word = "facetious";
> my $pos;
> while($word =~ m/([aeiou])/g) {
>     $pos = pos($word) - 1;
>     substr($newword, $pos, 1) = $newvowel{substr($word, $pos, 1)};
>     print "$newword\n";
> }

$newword =~ s/([aeiou])/$newvowel{$1}/g;

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 7 Jul 1998 23:27:14 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Pattern matching problems
Message-Id: <1dbtk3h.1qqhw1bns6h6hN@bay2-137.quincy.ziplink.net>

Larry Rosler <lr@hpl.hp.com> wrote:

> $newword =~ s/([aeiou])/$newvowel{$1}/g;

That changes all the vowels all at once, whereas the original poster
wanted to change one vowel, print the result, change the next vowel, and
so on.

I don't think it can be done using just a s///.  (Yes, /e would help,
but the prints would be in the wrong place. :-)

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 07 Jul 1998 21:02:41 -0500
From: Ernest Mueller <ernestm@towery.com>
Subject: Problem in Variable String to Open()
Message-Id: <35A2D341.86D48545@towery.com>

I am trying to call open() to pipe in the results from a command line
program being executed.  If I call it explicitly:

open FILE, "/my/command arg1 arg2 |";
@ans = <FILE>;
close FILE;

It works fine.  But if I make a variable ahead of time for the execution
string:

$arg1 = FORM{arg1}; # from a CGI handler
$arglist = "$command $arg1 $arg2";
open FILE, $arglist";

It fails.  If I set 
$arg1 = "a string";
it works, but with $arg1 = FORM{arg1} it doesn't.  If I print
FORM{arg1}, or $arg1 for that matter, it looks fine, but when I pass to
open() it never comes back.  I can compare them to the string directly
and get positive results.

Anyone know what's at work here?

Thanks,
Ernest
-- 
Ernest C. Mueller                               ernestm@towery.com
Webmaster                                       Phone: (901) 251-7000
Towery Publishing                               http://www.towery.com


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

Date: Tue, 07 Jul 1998 22:57:27 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Problem in Variable String to Open()
Message-Id: <comdog-ya02408000R0707982257270001@news.panix.com>
Keywords: from just another new york perl hacker

In article <35A2D341.86D48545@towery.com>, Ernest Mueller <ernestm@towery.com> posted:

>It works fine.  But if I make a variable ahead of time for the execution
>string:
>
>$arg1 = FORM{arg1}; # from a CGI handler

what is "FORM"? :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: 8 Jul 1998 02:42:18 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Problem in Variable String to Open()
Message-Id: <6numaa$ofv$1@comdyn.comdyn.com.au>

In article <35A2D341.86D48545@towery.com>,
	Ernest Mueller <ernestm@towery.com> writes:

> $arg1 = FORM{arg1}; # from a CGI handler

Did you mean $FORM{arg1} ?

Maybe you should consider running perl with the -w option, and
probably even with use strict. You should also consider checking
whether $FORM{arg1} actually has anything in it, which is not
dangerous.

Consider this:

# DO NOT TRY THIS IF YOU DON'T UNDERSTAND WHAT IT DOES
$arg1 = "; rm -rf /;";
$arg2 = 'irrelevant';
open(FILE, "$command $arg1 $arg2 |") || die "Couldn't open pipe: $!";

You should probably also read a bit in the perlfaq.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | That's not a lie, it's a terminological
Commercial Dynamics Pty. Ltd.       | inexactitude.
NSW, Australia                      | 


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

Date: Wed, 8 Jul 1998 01:16:51 +0200
From: vibes@hipdrome.org (Jxrn-Morten Innselset)
Subject: Proper locking of DBM files?
Message-Id: <MPG.100cd8de32a1d86f989694@d2o201.telia.com>

I'm writing an end user web frontend to a hash file used by Apache's 
rewrite module, and as usual I cut some corners by cutting and pasting 
code sniplets. I think my application is ready for it's first release - 
my only concern is simultanous access to the hash file through DB_File.

The question is - is the following enough to ensure that two users 
updating the file within the same split microsecond won't wreck my db?

tie %p,  DB_File, $passwd_db, O_RDWR|O_EXLOCK, undef, $DB_HASH

Oh yeah - running Perl 5.004_04 on FreeBSD 2.2.6-STABLE.

-- 
Don't be fooled. FreeBSD is UNIX, not a clone like Linux. FreeBSD or bust!


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

Date: 7 Jul 1998 21:18:14 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: question about objects
Message-Id: <6nuhcm$i52$1@monet.op.net>

In article <6nu509$sum$1@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
>    package UnderScore;
>    sub FETCH { croak "Read access to \$_ forbidden"  } 
>    sub unimport { tie($_, __PACKAGE__) }
>    sub import { untie $_ } 

Gosh, I wish I'd thought of this.  A package where `unimport' imports
a tied variable and `import' unimports it is just the kind of thing I
want to be writing.



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

Date: 8 Jul 1998 03:41:19 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: question about objects
Message-Id: <6nupov$3eq$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    mjd@op.net (Mark-Jason Dominus) writes:
:Gosh, I wish I'd thought of this.  A package where `unimport' imports
:a tied variable and `import' unimports it is just the kind of thing I
:want to be writing.

Strange, I didn't see any importing (read: symbol table assignments).
The point is that saying "no underscore" forbids use of dollar underscore,
and saying "use underscore" permits you to use it again.  Seems to 
be that this kind of "use" and "no" distinction is quite intuitive,
and that to go the other way would be extremely confusing.

--tom
-- 
> (It's sorta like sed, but not.  It's sorta like awk, but not.  etc.)
  Guilty as charged.  Perl is happily ugly, and happily derivative.
		--Larry Wall in <1992Aug26.184221.29627@netlabs.com>


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3089
**************************************

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