[18519] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 687 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 13 00:10:49 2001

Date: Thu, 12 Apr 2001 21:10:24 -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: <987135024-v10-i687@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 12 Apr 2001     Volume: 10 Number: 687

Today's topics:
    Re: CGI.pm V. Here Docs . . . (Mark Jason Dominus)
    Re: changing @INC permenently -- a caveat (Anthony Delorenzo)
        chatter bots paulthomson@hotmail.com
    Re: chatter bots (Gwyn Judd)
        chatterbots paulthomson@hotmail.com
    Re: communication between blocked parent and children a nobull@mail.com
    Re: communication between blocked parent and children a nobull@mail.com
    Re: dir problem (Gwyn Judd)
    Re: email related <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: File Upload <hartleh1@westat.com>
    Re: File Upload <ron@savage.net.au>
    Re: File Upload <uri@sysarch.com>
    Re: filecache tests -- abe's test <motivus-at-hotmail-dot-com>
        for each loop <no@spam.com>
    Re: for each loop (Jay Tilton)
    Re: for each loop <uri@sysarch.com>
    Re: for each loop <no@spam.com>
    Re: for each loop <steve_dob@totalise.co.uk>
    Re: for each loop <no@spam.com>
    Re: help needed with sorting Hash <kellikellin@netscape.net>
    Re: help needed with sorting Hash (Damian James)
        Help Required <bajwau@nortelnetworks.com>
    Re: Help Required <camerond@mail.uca.edu>
    Re: Help Required (Tad McClellan)
    Re: How can a SMTP mail be deleted from a Unix mailbox  <dnew@san.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 Apr 2001 19:00:32 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: CGI.pm V. Here Docs . . .
Message-Id: <3ad5fb4f.2026$2b@news.op.net>

In article <slrn9d64sa.m8d.rgarciasuarez@rafael.kazibao.net>,
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>Yes, cgi-lib is depreciated, and deprecated. 

I don't think you understand what 'deprecated' means.  "Deprecated"
does not make sense in this context.  The developers of Perl can say
when a Perl feature is 'deprecated'; this means that they will not
continue to support it, and that it might not be present in a future
version of Perl.

It does not make sense to say that 'cgi-lib is deprecated'.
Deprecated by whom?  By you?  Does that mean you will no longer
support it?  But you never promised to support it in the past, and
nobody expected you to support it, so revoking your support does not
matter.  Will it be absent from a future version of Perl?  So what?
It has never been included with Perl.

>No development is done on
>cgi-lib and no new versions are released. 

That is a good thing, not a bad thing.

No development is done because cgi-lib.pl is *complete*.
It does what it was designed to do, and it does it effectively.
No bugs have been reported in it for *six years*.

I would think that not having to constantly install new incompatible
versions of the same package would be a considered benefit.  Yuou can
be absolutely sure that your program will never break when you
'upgrade' to an incompatible version of cgi-lib.pl, because there are
no incompatible versions and no 'upgrades'.  

It is sad that greedy software companies have inured us to buggy,
incomplete software that is followed by an endless stream of
enhancements and bug fixes.  We have actually forgotten that this is
not the only kind of sofware that exists!  If we are told that there
is software with no bugs and no missing features, we cannot believe
it, and we suppose that there must be something wrong.

This is very frustrating to anyone who maintains a mature, effective
piece of software.  You have to field constant questions about why
there has not been a new release in nine months.  People are skeptical
when you tell them it is because there are no bugs and that no new
features are necessary.  They would rather assume that you have
abandoned the package.

>On the other hand, new versions of browsers and web servers are
>released. 

This is pure FUD.  CGI has not changed.  The current version is still
1.1, standardized in 1995.  CGI 1.2 was never completed, and no
servers support it.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 12 Apr 2001 18:08:08 GMT
From: ajdelore@sfu.ca (Anthony Delorenzo)
Subject: Re: changing @INC permenently -- a caveat
Message-Id: <9b4qu8$or3$1@morgoth.sfu.ca>

A further thing to keep in mind, at least under multi-user Unix systems,
is that scripts executed by such things as the web server or the cron
daemon may not include the user environment, depending on the system
configuration.

I have to install perl modules in my local directories.  I recently had a
horrible time trying to work-around some scripts that ran fine under a
log-in shell but then couldn't load the required modules for
non-interactive processes.

Further complicating the issue was that my cgi server didn't allow me to
modify @INC in any way.  As a kludge, I had to put symlinks in the cgi-bin
so that the scripts could find the modules in the current directory.

Tony

-- 
# Anthony DeLorenzo <ajdelore@sfu.ca>
# Burnaby, BC, Canada
# mojo wire: 209-391-8932
# http://www.sfu.ca/~ajdelore/


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

Date: Thu, 12 Apr 2001 23:15:51 GMT
From: paulthomson@hotmail.com
Subject: chatter bots
Message-Id: <3ad63719.21599021@news.homechoice.co.uk>

Hi,

Does anyone know of any chatter bots written in perl?

Thanks for any pointers,

Paul


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

Date: Fri, 13 Apr 2001 02:23:15 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: chatter bots
Message-Id: <slrn9dcooi.tmd.tjla@thislove.dyndns.org>

I was shocked! How could paulthomson@hotmail.com <paulthomson@hotmail.com>
say such a terrible thing:
>Does anyone know of any chatter bots written in perl?
>
>Thanks for any pointers,

http://www.google.com/search?q=chatter+bot+perl

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Algorithms" is an anagram for "Hilt orgasm".  Maybe this explains
the popularity of this field of study in computer science.


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

Date: Thu, 12 Apr 2001 23:15:04 GMT
From: paulthomson@hotmail.com
Subject: chatterbots
Message-Id: <3ad635da.21280010@news.homechoice.co.uk>

Hi,

Does anyone know of any chatter bots written in perl?

Thanks for any pointers,

Paul


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

Date: 12 Apr 2001 17:39:02 +0100
From: nobull@mail.com
Subject: Re: communication between blocked parent and children after fork
Message-Id: <u966ga5azd.fsf@wcl-l.bham.ac.uk>

alexf@hal9000.uni-koblenz.de (Alexander Fuchs) writes:
> I have a tcp server using IO::Socket::INET->new, i.e. listening
> on a tcp port. For each incoming connection a new process is
> immediatly forked, which should handle this connection.
> The parent process blocks and listens:
> 
>   while ($client = $server->accept ()) {
>     ..
>     elsif ($fork) {
>       close ($client);
>     } 
>     ...
>   } 
> 
> Because of performance reasons the parent process doesn't read
> anything of the incoming request.
> Now the problem occured, that some of the incoming requests should
> change the parent process status, e.g. it should reread its
> configuration file. As the parent doesn't know the request, the
> forked child has to tell him. But the parent is already
> blocked waiting for new requests.
> 
> So, how should the child inform its parent?

A pipe or socketpair would seem the obvious solution:

#!/usr/bin/perl
use warnings;
use strict;

use IO::Select;
use IO::Socket;

my $server = IO::Socket::INET->new( Listen => 5, LocalPort => 7777 );

pipe my ($from_child,$to_parent);
my $select = IO::Select->new($server,$from_child);

sub tell_parent {
    # I'm assuming fixed length messages for simplicity
    # must be less than PIPE_BUF to ensure that messages
    # from different children don't get mingled.
    syswrite $to_parent, pack 'La10@32', $$, shift;
}

while(1) {
    foreach my $fh ($select->can_read) {
	if($fh == $server) {
	    my $client = $server->accept () 
		or die "accept(): $!";
	    if (my $pid = fork()) {
		close $client;
		print "New child $pid created\n";
	    } elsif (defined $pid) {
		# Child
		close $from_child;
		tell_parent 'hello';
		while (<$client>) {
		    tell_parent "$1" if /^p(.*)/;
		}
		tell_parent 'goodbye';
	    } else {
		die "fork(): $!";
	    }
	} elsif ($fh == $from_child ) {
	    sysread $from_child, my($packet), 32;
	    my ( $pid, $message ) = unpack 'La10', $packet;
	    print "Child $pid says $message\n";
	} else {
	    die;
	}
    }
}

__END__

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 12 Apr 2001 18:04:17 +0100
From: nobull@mail.com
Subject: Re: communication between blocked parent and children after fork
Message-Id: <u9wv8q3v8u.fsf@wcl-l.bham.ac.uk>

nobull@mail.com writes:

> 	    } elsif (defined $pid) {
> 		# Child
> 		close $from_child;
> 		tell_parent 'hello';
> 		while (<$client>) {
> 		    tell_parent "$1" if /^p(.*)/;
> 		}
> 		tell_parent 'goodbye';
> 	    } else {

Oops missing exit()!

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 13 Apr 2001 01:50:31 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: dir problem
Message-Id: <slrn9dcmr6.tmd.tjla@thislove.dyndns.org>

I was shocked! How could J.A.W <nlp0421@gz.cngb.com>
say such a terrible thing:
>
>foreach $file (@FILES) {
> $f=$file;
> next if -d $f;
>}
>
>but some subdirs still fails to be left out, particularly those ".files"
>ones. Why does this happen?

Well the above code doesn't appear to "leave out" anything. Yu don't
seem to do anything following the "next" statement. Have you left
something out?

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
IMPOSTOR

n. A rival aspirant to public honors.


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

Date: 13 Apr 2001 01:25:56 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: email related
Message-Id: <86ofu14ml7.fsf@jon_ericson.jpl.nasa.gov>

Bing Du <bing-du@tamu.edu> writes:

> Is there any mail related Perl module that can deliver email directly to
> the folder (mailbox)?  We use IMAP server. Some shared folders are
> created on the server for the students to subscribe to read official
> announcements.  Now we need to write a CGI program in Perl to let the
> directors, department heads, et. al. to be able to use the web interface
> to send the announcement to the shared folder.

Have you explored CPAN (search.cpan.org)?  Mail::IMAPClient might be
what you are looking for.

Jon


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

Date: Thu, 12 Apr 2001 14:54:29 -0400
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: File Upload
Message-Id: <3AD5F9E5.716334D8@westat.com>

james freeman wrote:
> >Original Message From "Vassilis G. Tavoultsidhs" <ixanthi@ixanthi.gr>
> >I am trying to create a cgi script which will send among other things and a
> >file to the server in a specified location. I have made the form in HTML but
> >I don't know how to handle the file which I get from it in order to send it
> >to my server. Anybody who has any idea please help.
> >
> There are two very well know scripts that aid with CGI tasks,
> including file upload. These are cgi-lib.pm and CGI.pm
> 
> Look up CGI.pm here:
> http://stein.cshl.org/WWW/software/CGI/
> 
> or look up cgi-lib.pl here:
> http://cgi-lib.berkeley.edu/

And then learn and use CGI.pm

-- 
Henry Hartley


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

Date: Fri, 13 Apr 2001 13:19:02 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: File Upload
Message-Id: <QntB6.631$EQ3.22761@ozemail.com.au>

Keep an eye on this page: http://savage.net.au/Perl-tutorials.html

I'll try to upload a 'File upload' tutorial sometime in the next few days.

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html
Vassilis G. Tavoultsidhs <ixanthi@ixanthi.gr> wrote in message news:987062486.536837@athnrd02.forthnet.gr...
> I am trying to create a cgi script which will send among other things and a
> file to the server in a specified location. I have made the form in HTML but
> I don't know how to handle the file which I get from it in order to send it
> to my server. Anybody who has any idea please help.





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

Date: Fri, 13 Apr 2001 03:59:27 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: File Upload
Message-Id: <x74rvto3fl.fsf@home.sysarch.com>

>>>>> "RS" == Ron Savage <ron@savage.net.au> writes:

  RS> Keep an eye on this page: http://savage.net.au/Perl-tutorials.html
  RS> I'll try to upload a 'File upload' tutorial sometime in the next few days.

why do you call those tutorials when there is no explanatory text? 

i just decided to look at one of them to see what you are doing. i did
not like what i saw. besides the odd indenting and formatting style, i
don't see any descriptions of what the code is doing or many
comments. so how is someone going to learn from this other than to
cargo-cult it into their programs?

here is a chunk of your CGI-Exploreer.pm. not one comment in or near
this code. you use the same name for a scalar and a list which can be
confusing. and you always seem to use

	$$myself{'_id'}

instead of the much clearer (and more commonly used)

	$myself->{'_id'}

i didn't change the formatting which is downright odd all over the
place. why are some lines wrapped which don't have to be and others
which should be are not? the expressions towards the bottom are very
impenetrable. they could be rewritten with much cleaner code. you don't
use autovivification where you can.


         for my $bit (@bit)
        {
                $parent = $prefix;
                $prefix .= "/$bit";

                next if (${$$myself{'_seen'} }{$prefix});

                $$myself{'_id'}++;

                ${$$myself{'_seen'} }{$prefix}                                  
= $$myself{'_id'};
                ${$$myself{'_tree'} }{$$myself{'_id'} }                 = {};
                ${$$myself{'_tree'} }{$$myself{'_id'} }{'id'}   = $$myself{'_id'
};
                ${$$myself{'_tree'} }{$$myself{'_id'} }{'name'} = $prefix;
                my($parent_id)                                                  
                = 0;

                for my $key (keys %{$$myself{'_tree'} })
                {
                        $parent_id = ${$$myself{'_tree'} }{$key}{'id'} if ($pare
nt eq ${$$myself{'_tree'} }{$key}{'name'});
                }

                ${$$myself{'_tree'} }{$$myself{'_id'} }{'parent_id'} = $parent_i
d;
        }

}      


that is not good code to teach with. it is listed as one of your
tutorials but is is just that module and a test script and module
packaging. please don't call or advertise that as a tutorial.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 12 Apr 2001 10:46:08 -0700
From: "bmm" <motivus-at-hotmail-dot-com>
Subject: Re: filecache tests -- abe's test
Message-Id: <9b4pbj$d2$1@slb5.atl.mindspring.net>


"Abe Timmerman" <abe@ztreet.demon.nl> wrote in message
news:1a57dtgs6d2fg3kpr7keqjp8d9fat5g2uh@4ax.com...
> [ If you want to follow-up, please do so in the actual thread. Now this
> subject is al over the place. ]
>

You are right, of course. Sorry about that. I don't know how other people's
news readers work, but with mine posts to relatively old threads (even days
old) can go unnoticed. And I wasn't certain I could get your attention
again.

> On Tue, 10 Apr 2001 12:34:19 -0700, "B McDonald" <plz@righthere.com>
> wrote:
>
> >
> > Hi. I'm still trying to figure out how to use FileCache in order to
write
> > data to 12 simultaneously open files. My OP was on 4/4/2001.
> >
> [ snip of code that lost indentation ]
> >
> > First, does anyone know how I can specify that the file be opened for
> > appending? Presently, this writes over the prior contents of each file.
>
> Well it is not accommodated for, but you can use a hack. Set
>
> $FileCache::saw{ $filename }++;
>
> before the first call to
>
> cacheout $filename;
>
> and by the nature of the module, it opens for appending.
>

Anyway, I haven't tried this yet -- I've been swamped by other work. But
I'll give the source code a look and try this "hack" later on today. Thanks.

> You might want to read the sourcecode of that module, its not that hard
> to understand.
>
> perldoc -m FileCache
>
> --
> Good luck, Abe
> Amsterdam Perl Mongers  http://amsterdam.pm.org
> perl -e '$_=sub{split//,pop;print pop while@_};&$_("rekcah lreP rehtona
tsuJ")'




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

Date: Thu, 12 Apr 2001 21:15:16 GMT
From: Borgy <no@spam.com>
Subject: for each loop
Message-Id: <3AD61AD3.FDFDEFF5@spam.com>

I am having trouble getting the Total for TAX1.
All items should have TAX1 applied to them unless
they have the string 'book' within them. I can't seem
to get the correct $TAX1 total. For example say you had
one item at 19.99 that TAX1 applied to and another at 18.99
that $TAX1 did NOT apply to, the Total for TAX1 should be
$1.60 (8% of the item at 19.99).

Any help would be GREATLY appreciated! Thanks, Borgy

##### for each item that contains the word 'book' do not apply TAX1 .08
 
foreach $cooky (@cooky) {
($quantity, $price, $item) = split(/:/, $cooky);
 $ItemTotal = $quantity * $price;
    if ($item !~/(book)/) {
       $TAX1=($quantity*$price)*.08;
       $TAX1=sprintf("%.2f", $price);
       }
 $RunningTotal = $RunningTotal + $ItemTotal;
}

 $TheTotal = $RunningTotal;
 $TAX2=$TheTotal*.07;
 $TAX2=sprintf("%.2f", $TAX2);
 $GrandTotal=$TheTotal+$TAX1+$TAX2;
 $GrandTotal=sprintf("%.2f", $GrandTotal);


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

Date: Thu, 12 Apr 2001 22:02:30 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: for each loop
Message-Id: <3ad62049.18879967@news.erols.com>

On Thu, 12 Apr 2001 21:15:16 GMT, Borgy <no@spam.com> wrote:

>I am having trouble getting the Total for TAX1.
>All items should have TAX1 applied to them unless
>they have the string 'book' within them. I can't seem
>to get the correct $TAX1 total. For example say you had
>one item at 19.99 that TAX1 applied to and another at 18.99
>that $TAX1 did NOT apply to, the Total for TAX1 should be
>$1.60 (8% of the item at 19.99).

Sounds like a homework problem.

>##### for each item that contains the word 'book' do not apply TAX1 .08
> 
>foreach $cooky (@cooky) {
>($quantity, $price, $item) = split(/:/, $cooky);
> $ItemTotal = $quantity * $price;
>    if ($item !~/(book)/) {

You might want to make that regex case-insensitive.

>       $TAX1=($quantity*$price)*.08;
>       $TAX1=sprintf("%.2f", $price);
                              ^^^^^^
That ain't right.

>       }
> $RunningTotal = $RunningTotal + $ItemTotal;
>}

You're not keeping track of $TAX1 for each item.  The last value that
is calculated is the only one available beyond the loop.


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

Date: Thu, 12 Apr 2001 22:10:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: for each loop
Message-Id: <x7g0fdojlg.fsf@home.sysarch.com>

>>>>> "B" == Borgy  <no@spam.com> writes:

  B> I am having trouble getting the Total for TAX1.
  B> All items should have TAX1 applied to them unless
  B> they have the string 'book' within them. I can't seem
  B> to get the correct $TAX1 total. For example say you had
  B> one item at 19.99 that TAX1 applied to and another at 18.99
  B> that $TAX1 did NOT apply to, the Total for TAX1 should be
  B> $1.60 (8% of the item at 19.99).

  B> ##### for each item that contains the word 'book' do not apply TAX1 .08
 
  B> foreach $cooky (@cooky) {

it is usually spelled cookie.

  B> ($quantity, $price, $item) = split(/:/, $cooky);

make those variables private with my()

  B>  $ItemTotal = $quantity * $price;

mixed cased names is not common with perl. use _ to separate parts of names.

  B>     if ($item !~/(book)/) {

	unless( $item =~ /(book)/ ) {

same thing but clearer. !~ is only needed in a few places.


  B>        $TAX1=($quantity*$price)*.08;
  B>        $TAX1=sprintf("%.2f", $price);

why are you assigning to $TAX1 and then assigning to it again?
do you mean to format the value of $TAX1 to 2 digits?

	$TAX1 = sprintf( "%.2f",  $ItemTotal * .08 ) ;

you never do any summing with $TAX1. you need to sum it in another
variable or make it a running sum.

	$tax1_sum += $TAX1 ;

and be sure to clear it before the loop

  B>        }
  B>  $RunningTotal = $RunningTotal + $ItemTotal;

	$RunningTotal += $ItemTotal;


  B>  $TheTotal = $RunningTotal;

why do that? you don't need another variable.

  B>  $TAX2=$TheTotal*.07;
  B>  $TAX2=sprintf("%.2f", $TAX2);

same as before, no need for 2 steps:

	$TAX2 = sprintf( "%.2f", $RunningTotal * .07 ) ;

  B>  $GrandTotal=$TheTotal+$TAX1+$TAX2;

that $TAX1 is just the value from the broken code in the /book/ block.

  B>  $GrandTotal=sprintf("%.2f", $GrandTotal);

again, do this in one step.

use more whitespace, it will help in reading your code.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 12 Apr 2001 22:12:02 GMT
From: Borgy <no@spam.com>
Subject: Re: for each loop
Message-Id: <3AD62821.5D1A4069@spam.com>


Still there must be a way to keep the total in a variable and increment
it? ie. $TAX1++

 
> You might want to make that regex case-insensitive.
> 
> >       $TAX1=($quantity*$price)*.08;
> >       $TAX1=sprintf("%.2f", $price);   <- should be $TAX1
>                               ^^^^^^
> That ain't right.

It was a typo on my part!


> 
> >       }
> > $RunningTotal = $RunningTotal + $ItemTotal;
> >}
> 


Nope. I have seen variables incrementing each value to Give a total...

> You're not keeping track of $TAX1 for each item.  The last value that
> is calculated is the only one available beyond the loop.


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

Date: Thu, 12 Apr 2001 21:57:13 GMT
From: "Stephen Dobinson" <steve_dob@totalise.co.uk>
Subject: Re: for each loop
Message-Id: <ZwpB6.13322$4S3.4953276@news2.cableinet.net>

> foreach $cooky (@cooky) {
> ($quantity, $price, $item) = split(/:/, $cooky);
>  $ItemTotal = $quantity * $price;
>     if ($item !~/(book)/) {
>        $TAX1=($quantity*$price)*.08;
>        $TAX1=sprintf("%.2f", $price);

The line above overwrites the previous TAX1 calculation

You are not storing a running total of TAX1 for later use

--
Stephen Dobinson




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

Date: Thu, 12 Apr 2001 22:23:02 GMT
From: Borgy <no@spam.com>
Subject: Re: for each loop
Message-Id: <3AD62AB5.A6BEAC62@spam.com>

Good Answer!!! That helped a lot. Thank You. I will tighten up the code.

thanks,
Borgy
_______________



Uri Guttman wrote:
> 
> >>>>> "B" == Borgy  <no@spam.com> writes:
> 
>   B> I am having trouble getting the Total for TAX1.
>   B> All items should have TAX1 applied to them unless
>   B> they have the string 'book' within them. I can't seem
>   B> to get the correct $TAX1 total. For example say you had
>   B> one item at 19.99 that TAX1 applied to and another at 18.99
>   B> that $TAX1 did NOT apply to, the Total for TAX1 should be
>   B> $1.60 (8% of the item at 19.99).
> 
>   B> ##### for each item that contains the word 'book' do not apply TAX1 .08
> 
>   B> foreach $cooky (@cooky) {
> 
> it is usually spelled cookie.
> 
>   B> ($quantity, $price, $item) = split(/:/, $cooky);
> 
> make those variables private with my()
> 
>   B>  $ItemTotal = $quantity * $price;
> 
> mixed cased names is not common with perl. use _ to separate parts of names.
> 
>   B>     if ($item !~/(book)/) {
> 
>         unless( $item =~ /(book)/ ) {
> 
> same thing but clearer. !~ is only needed in a few places.
> 
>   B>        $TAX1=($quantity*$price)*.08;
>   B>        $TAX1=sprintf("%.2f", $price);
> 
> why are you assigning to $TAX1 and then assigning to it again?
> do you mean to format the value of $TAX1 to 2 digits?
> 
>         $TAX1 = sprintf( "%.2f",  $ItemTotal * .08 ) ;
> 
> you never do any summing with $TAX1. you need to sum it in another
> variable or make it a running sum.
> 
>         $tax1_sum += $TAX1 ;
> 
> and be sure to clear it before the loop
> 
>   B>        }
>   B>  $RunningTotal = $RunningTotal + $ItemTotal;
> 
>         $RunningTotal += $ItemTotal;
> 
>   B>  $TheTotal = $RunningTotal;
> 
> why do that? you don't need another variable.
> 
>   B>  $TAX2=$TheTotal*.07;
>   B>  $TAX2=sprintf("%.2f", $TAX2);
> 
> same as before, no need for 2 steps:
> 
>         $TAX2 = sprintf( "%.2f", $RunningTotal * .07 ) ;
> 
>   B>  $GrandTotal=$TheTotal+$TAX1+$TAX2;
> 
> that $TAX1 is just the value from the broken code in the /book/ block.
> 
>   B>  $GrandTotal=sprintf("%.2f", $GrandTotal);
> 
> again, do this in one step.
> 
> use more whitespace, it will help in reading your code.
> 
> uri
> 
> --
> Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
> SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
> Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
> Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 12 Apr 2001 13:34:05 -0500
From: kelli norman <kellikellin@netscape.net>
Subject: Re: help needed with sorting Hash
Message-Id: <3AD5F51D.1A5C53B5@netscape.net>

such friendly people out there!

there is no way to actually make a hash have it's keys in sorted order,
but if you just want to print the values in order:

foreach $value (sort values %hash)
{ print "$value\n"; }

or see:
http://www.devdaily.com/perl/edu/qanda/plqa00016/
and:
http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlfaq4/How_do_I_look_up_a_hash_element_by_value_.html

---
afshin akbari wrote:
> 
> All,
> 
> Is there a way to to sort and print a hash based on the
> value field.
> 
> suppose we have,
> 
> %hash (a => 7,
>         b => 1,
>         c => 3);
> 
> result should be:
> 
> %hash (b => 1,
>         c => 3,
>         a => 7);
> 
> Thanks in advance.
> aa-


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

Date: 12 Apr 2001 22:53:27 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: help needed with sorting Hash
Message-Id: <slrn9dcccs.a03.damian@puma.qimr.edu.au>

afshin akbari chose Wed, 04 Apr 2001 02:20:57 GMT to say this:
>...
>Is there a way to to sort and print a hash based on the 
>value field. 
>

This is a FAQ. See:

	perldoc -q hash
	"How do I look up a hash element by value?"

In short, create a reverse lookup hash:

	[untested]
	my $lookup = reverse %original;
	print "$lookup{$_} = $_\n" for sort keys %lookup;

See also:

	perldoc -f reverse

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;){;(
$:=rand$;+$|)==$;&&next;@;[$;,$:]=@;[$:,$;]}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3 -- a JAPH in progress, I guess...


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

Date: Thu, 12 Apr 2001 16:08:10 -0400
From: Umair Bajwa <bajwau@nortelnetworks.com>
Subject: Help Required
Message-Id: <3AD60B2A.685C389@nortelnetworks.com>

I would like to provide a link for the users to download the file into
their home directory. In the code if I use file name <filename>.etx it
works fine. But if I use <filename>.pdf it runs the acrobat reader and
open the file right into it. 
Does any one have any idea instead of opening into the acrobat reader
how should i force the perl to pop up the window and ask for the file
name. Thanks in advance

Umair


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

Date: Thu, 12 Apr 2001 15:38:13 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Help Required
Message-Id: <3AD61235.D3A13C13@mail.uca.edu>

Umair Bajwa wrote:
> 
> I would like to provide a link for the users to download the file into
> their home directory. In the code if I use file name <filename>.etx it
> works fine. But if I use <filename>.pdf it runs the acrobat reader and
> open the file right into it.
> Does any one have any idea instead of opening into the acrobat reader
> how should i force the perl to pop up the window and ask for the file
> name. Thanks in advance
> 
> Umair

Pure and simple, you can't unless you rename the extension. Their
browser is going to do whatever it wants with the file.

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Thu, 12 Apr 2001 17:31:16 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help Required
Message-Id: <slrn9dc7l4.erg.tadmc@tadmc26.august.net>

Umair Bajwa <bajwau@nortelnetworks.com> wrote:

>Subject: Help Required


Subject required.


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


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

Date: Thu, 12 Apr 2001 16:26:41 GMT
From: Darren New <dnew@san.rr.com>
Subject: Re: How can a SMTP mail be deleted from a Unix mailbox by a script?
Message-Id: <3AD5D743.23354E84@san.rr.com>

Logan Shaw wrote:
> If you used the .forward file to specify that the message goes to a
> program, it should go to the program and not to a mailbox.  That is,
> unless you specified that the message should go to both, but I don't
> know why you'd send it to two places and do nothing but immediately
> delete it from one.

You have to return with the right error code. Returning with exit(0) will
say that you've processed the mail. Other exit codes will leave the mail
queued for delivery the next time around, or bounce the message. (This is
assuming you're using sendmail. There are probably ways to do this with
other programs.)
 
> >- What actions must be performed to remove the specific mail from the mbox
> >file?
> 
> It's a file.  It's in a certain format.  You just have to understand
> the format, be able to parse it, and be able to write a modified
> version out.

You also have to know how to lock it, so that you're not writing it out
while new mail is being appended.

-- 
Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
San Diego, CA, USA (PST).  Cryptokeys on demand.
        schedule.c:7: warning: assignment makes calendar_week 
                          from programmer_week without a cast.


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

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


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