[13960] in Perl-Users-Digest
Perl-Users Digest, Issue: 1370 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 13 18:10:45 1999
Date: Sat, 13 Nov 1999 15:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942534614-v9-i1370@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 13 Nov 1999 Volume: 9 Number: 1370
Today's topics:
Re: searching flatfile with a hash <ben@smooth.co.uk>
Re: searching flatfile with a hash (Kragen Sitaker)
Show me a better way! <JFedor@datacom-css.com>
Re: Show me a better way! (Kragen Sitaker)
Re: Show me a better way! <jeff@vpservices.com>
simulating buffer file with variable <ask_for_my_address_if_you_need_it@earthlink.net>
Thanks to all Re: Help me 'Think Perl' <hmarq@interaccess.com>
thanks <reembar@netvision.net.il>
Re: Too much Perl? (Kragen Sitaker)
Re: What format does DBI:CSV create a new table in? (Kragen Sitaker)
What module for adding messages to mail folders? <steffi@shell8.ba.best.com>
Which browser? <christian@wix.dk>
Re: Why Doesn't This Work on ICOM? (Kragen Sitaker)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 13 Nov 1999 19:04:38 -0000
From: Ben Osman <ben@smooth.co.uk>
Subject: Re: searching flatfile with a hash
Message-Id: <MPG.1297c6a28c214b34989681@news.btinternet.com>
hi there
> Hmm, you really need to read
> http://photo.net/wtr/thebook/databases-choosing.html. Don't worry --
> it's a fun read, and it should leave you shaking your head, saying,
> "Why did I ever do it that way?"
thanks will check it out
>
> I don't understand. You mean you have a hash created by statements like
> $allproductshash{$product_id}->{$quantity} = 'true'; ? Or
> @edible_lingerie_hash{'id', 'quantity'} = ('xxx6969', 20); Or what?
>
it is from opening another textfile with the cart data in - I used a
while loop to push them in to the following array and hash.
e.g $open_cart_row[$array_item]{id} = $product_id;
$array_item is used to place each item in a separate hash within the
array.
why? you may ask..
well I need to check each item so the price and stock levels are upto
date and the product actually exists. and I will need to pass the whole
array to template system for display -
the whole thing is in a subroutine - so I can call it within different
contexts - (i am using references)
thanks
ben
------------------------------
Date: Sat, 13 Nov 1999 19:35:06 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: searching flatfile with a hash
Message-Id: <K3jX3.7224$YI2.284859@typ11.nn.bcandid.com>
In article <MPG.1297c6a28c214b34989681@news.btinternet.com>,
Ben Osman <ben@smooth.co.uk> wrote:
>> I don't understand. You mean you have a hash created by statements like
>> $allproductshash{$product_id}->{$quantity} = 'true'; ? Or
>> @edible_lingerie_hash{'id', 'quantity'} = ('xxx6969', 20); Or what?
>
>it is from opening another textfile with the cart data in - I used a
>while loop to push them in to the following array and hash.
>e.g $open_cart_row[$array_item]{id} = $product_id;
>$array_item is used to place each item in a separate hash within the
>array.
OK, now I understand.
You need to read your datafile and create hashes of it; the general
pattern is like this:
while (<DATAFILE>) {
my ($id, $price, $category, $whatever) = split /\|/;
# do something with the data
}
The 'do something' section might be:
$productinfo{$id} = [$price, $category, $whatever];
or
$price{$id} = $price;
$category{$id} = $category;
$whatever{$id} = $whatever;
(although you don't have to call the hashes the same as the scalars as I did)
or
$productinfo{$id} = {price => $price,
category => $category,
whatever => $whatever};
. . . depending on your preferences. I'd vote for the second one
unless I wanted to do more than just look things up.
>well I need to check each item so the price and stock levels are upto
>date and the product actually exists. and I will need to pass the whole
>array to template system for display -
So if the stock level is 1, and the quantity requested is 1, you're
going to send back an 'order will ship today' page and update the stock
level? What happens if you do this to two customers at the same time?
What happens if somebody is updating the price as you read the product
database? You *really* should read that web page I mentioned, or
you're going to have some very unhappy customers.
Anyway, you can either denormalize your $open_cart_row for convenience,
with $open_cart_row[$array_item]{price} =
$price{$open_cart_row[$array_item]{id}};, or you can just look at
$price{that stuff above} every time you want the price.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Sat, 13 Nov 1999 14:35:55 -0500
From: "Jody Fedor" <JFedor@datacom-css.com>
Subject: Show me a better way!
Message-Id: <80kdbe$28q$1@plonk.apk.net>
I know this isn't bad when only doing a few comparisons
but if there were 10 or 20 the code would be functional
but a nitemare. How could it be written simpler?
if ($cookies{'state'} eq "OH") {$tax = ($tcost * .055) + .005}
elsif ($in{'fstate'} eq "OH") {$tax = ($tcost * .055) + .005}
else {$tax = 0.00};
TIA,
Jody
------------------------------
Date: Sat, 13 Nov 1999 19:45:52 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Show me a better way!
Message-Id: <QdjX3.7275$YI2.286552@typ11.nn.bcandid.com>
In article <80kdbe$28q$1@plonk.apk.net>,
Jody Fedor <JFedor@datacom-css.com> wrote:
>I know this isn't bad when only doing a few comparisons
>but if there were 10 or 20 the code would be functional
>but a nitemare. How could it be written simpler?
>
>if ($cookies{'state'} eq "OH") {$tax = ($tcost * .055) + .005}
>elsif ($in{'fstate'} eq "OH") {$tax = ($tcost * .055) + .005}
>else {$tax = 0.00};
Are you talking about 10 or 20 different states, 10 or 20 different
hashes you might have to check to see if somebody is in Ohio, or 10 or
20 different factors (city, county, neighborhood) to decide what tax
rate to charge?
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 13 Nov 1999 20:49:02 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Show me a better way!
Message-Id: <382DCE76.C684F558@vpservices.com>
Jody Fedor wrote:
>
> I know this isn't bad when only doing a few comparisons
> but if there were 10 or 20 the code would be functional
> but a nitemare. How could it be written simpler?
>
> if ($cookies{'state'} eq "OH") {$tax = ($tcost * .055) + .005}
> elsif ($in{'fstate'} eq "OH") {$tax = ($tcost * .055) + .005}
> else {$tax = 0.00};
I'd lose the ifs and use hashes and ors.
my $state = $cookies{state} || $in{fstate} || '';
my %rate = (
OH => { times_rate => .055, plus_rate => .005 },
TX => { times_rate => .066, plus_rate => .006 },
# etc. for all states that have taxes
);
my $tax = ( $tcost * $rate{$state}{times_rate} )
+ $rate{$state}{plus_rate};
--
Jeff
------------------------------
Date: Sat, 13 Nov 1999 12:23:59 -0800
From: Phil <ask_for_my_address_if_you_need_it@earthlink.net>
Subject: simulating buffer file with variable
Message-Id: <382DC8DF.713E206B@earthlink.net>
Hello and thanks for your help.
I recently wrote this little client/server in which the user enters some
perl code and it gets executed on the server. I wanted the output to be
sent back to the client, but I didn't want the user the have to alter
their code. IE:
sending this to the server:
print 'hi';
should return simply;
hi
That being the case, I created a buffer file associated with <BUFFER>
and selected it on the server end, thereby transparently sending the
user output to the file. I later read this file and return the content
to the client.
Unfortunately, this involves a buffer file and the associated I/O, which
I want to avoid.
I could make the user type:
$buffer .= 'hi';
and send $buffer to the client, but that seems a bit awkward to me.
So, the question is, 'how can I transparently have a variable act as a
filehandle without an associated file?'
Thanks,
Phil
------------------------------
Date: Sat, 13 Nov 1999 13:07:16 -0600
From: "Hank Marquardt" <hmarq@interaccess.com>
Subject: Thanks to all Re: Help me 'Think Perl'
Message-Id: <s2rdqktghsq35@corp.supernews.com>
How cool is this??!! I post at 9am on a Saturday and by 10:30 a handful of
useful replies!
To those who responed, Thank You! I knew the problem had to be easier than
I was making it ... and how. I think the best one had reduced it to 2 lines
of code, that I was prepared to basically write a 'C-like' parsing engine
over:)
I know it's all mind set, I just have to get used to shifting the gears.
------------------------------
Date: Sat, 13 Nov 1999 20:18:04 +0200
From: Re'em Bar <reembar@netvision.net.il>
Subject: thanks
Message-Id: <382DAB5C.30FB7B6F@netvision.net.il>
--
Re'em
http://snark.co.il
------------------------------
Date: Sat, 13 Nov 1999 20:21:40 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Too much Perl?
Message-Id: <oLjX3.7403$YI2.291601@typ11.nn.bcandid.com>
In article <slinberg-1211991404500001@bsg-ma2d-179.ix.netcom.com>,
Steve Linberg <slinberg@crocker.com> wrote:
>I still feel, though, that I need to get back to doing more C. C is the
>mother tongue, after all, and I feel I'm being disloyal to the mother.
>Perl is doing too much work for me, managing all my variables and memory,
>giving me English-like constructs to manipulate text and language with.
>It's gotten too easy. I've forgotten how to write a complete application
>with an interface. In a way, I fear I'm losing my edge as a
>once-hard-core, close-to-the-iron programmer. Perl lets me do wonderful
>things, but I feel I'm a little too removed from the metal. I don't want
>to wake up a script kiddie one day.
>
>Just wondering if any other Perl hackers experience this sensation. Maybe
>it's the uptight blueblood Yankee in me, feeling that I'm not suffering
>enough and that I need more penance, that I've got it too easy. :) Maybe
>people in Californina don't experience this. I wonder.
Yes, I feel this way sometimes. Occasionally, because of this feeling,
I have done the following things:
- walk from town to town instead of driving;
- read my email with 'less' instead of using a mailreader;
- buy Apple IIs with plans of writing assembly for them;
- send email by editing a file with 'vi' and then handing it to
sendmail instead of using a mailreader;
- read HTML with 'less' instead of using a web browser;
- use a Sun 3/60 running NetBSD as my desktop machine;
- write programs in Forth;
- build concrete molds to help friends pour their garage foundations;
- bicycle to work;
- use IRC via telnet ircserver 6667.
But I generally go back to more convenient ways of doing things.
I write things in C sometimes, but mostly when the problem isn't any
better suited to Perl than to C.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Sat, 13 Nov 1999 19:19:59 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: What format does DBI:CSV create a new table in?
Message-Id: <zRiX3.7044$YI2.282537@typ11.nn.bcandid.com>
In article <80jbel$941$1@nnrp1.deja.com>, <tony_123@my-deja.com> wrote:
>I have been having some problems with DBI:CSV.
>The problem is, if I write a program that creates and populates that
>table then I can write a program that can successfully read that table
>and output its contents. If however I create the input to the program
>that just reads and then displays the table in vi then the program does
>not work.
I don't understand.
> When I look at each input file in vi with the
>
>:set list
>
>option (This shows any control characters in the file)
> then both files appear identical, however if I do a checksum on each
>file then it shows they are different.
>Does anyone know what is going one?
Consider using diff on the two files. If you have XEmacs or GNU Emacs
with X, run them and use M-x ediff-files, which will show you exactly
which words differ.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 13 Nov 1999 12:14:14 -0800
From: Robert Nicholson <steffi@shell8.ba.best.com>
Subject: What module for adding messages to mail folders?
Message-Id: <yl3k8nmgne1.fsf@shell8.ba.best.com>
I going to assume CPAN is out of date.
is Mail::Folder the way to go if you want to safely add email messages
to mail folders?
What about GBARRs Mail::Util?
------------------------------
Date: Sat, 13 Nov 1999 23:47:58 +0100
From: Christian Wix <christian@wix.dk>
Subject: Which browser?
Message-Id: <382DEA9D.4664A2E0@wix.dk>
Hello!
How can I determine which browser people are using when they visit my
my web page? The web page is private so the visitors are filling out a
form (user name/password) when they login and the data is stored with
post/QUERY_STRING. So can I automatically pass the browser information
with "post" or can perl receive itself? How do I do it?
// Chris
--
Christian Wix
Bergsøekollegiet 23,st - 2309
Søllerød
2850 Nærum
Denmark
Phone: +45 45505171-(tone)-2309 / +45 26258162
Email & www: mailto:christian@wix.dk - http://www.wix.dk
ICQ #21322285
------------------------------
Date: Sat, 13 Nov 1999 19:59:46 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Why Doesn't This Work on ICOM?
Message-Id: <SqjX3.7325$YI2.288458@typ11.nn.bcandid.com>
In article <382c8928.175834482@news-server>, Kendar <heron@hell.com> wrote:
>Why doesn't the following work on ICOM?
>
>Here is the little piece of code:
>
><a href="/cgi-bin/track.cgi?os=www.soulis.com/search.html">
><img src="http://www.soulis.com/banners/cyberg.gif" border="0"
>alt="Cyberg"></a>
That's not code. That's HTML.
>Is there another way to execute the CGI program?
>Every time I try any such configuration I get the ERROR:
>
>Script execution error
>Unable to execute script due to a configuration problem.
>Please notify the webmaster of this error.
>exec() returned: 2: No such file or directo
>
>But I have CHMODes everything correctly and all
>files are configured right!
Maybe your CGI script is in the wrong directory. Maybe your #! line at
the beginning of the script refers to the wrong location for the Perl
interpreter. Or maybe the web server is upset that you misspelled
"cyborg", but I doubt it.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1370
**************************************