[16464] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3876 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 1 21:05:35 2000

Date: Tue, 1 Aug 2000 18:05:13 -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: <965178313-v9-i3876@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 1 Aug 2000     Volume: 9 Number: 3876

Today's topics:
    Re: Beginner CGI question (David Efflandt)
    Re: Configure Win32::ODBC Connection to a SQL Server? <eyalb@aks.com>
    Re: Convert 1000000 --> 1.000.000 <chucko@purewaterstores.com>
    Re: Copy a hash and const? <dietmar.staab@t-online.de>
    Re: Copy a hash and const? <dietmar.staab@t-online.de>
    Re: Copy a hash and const? <lr@hpl.hp.com>
    Re: Copy a hash and const? <lr@hpl.hp.com>
    Re: Detecting end of HTTP reply (David Efflandt)
    Re: dialing from another computer <hugh.brian@uengineer.com>
    Re: Dynamic String to hash <kenhare@ultrapresence.com>
    Re: Dynamic String to hash <mauldin@netstorm.net>
    Re: How to use "touch" in perl (Otto Wyss)
    Re: How to use "touch" in perl <lr@hpl.hp.com>
    Re: I have an idea but will it work ? <globalcon2@myhouse.com>
    Re: I have an idea but will it work ? <globalcon2@myhouse.com>
        Net::FTP Module <troyr@vicnet.net.au>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 2 Aug 2000 00:56:21 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Beginner CGI question
Message-Id: <slrn8oesdg.fkd.efflandt@efflandt.xnet.com>

On Tue, 01 Aug 2000 20:37:30 GMT, David Tsai <templar318@earthlink.net> wrote:
>
>The most "airtight" way would be to make your users register and make them
>confirm their email address.  That can be a hassle and would probably make
>most of your users just not participate in your poll.  The only other
>hassle free ways for your users is to use cookies and log their ip.
>However, most users will have dynamic IP addresses so cookies with
>temperary IP logging would be the best way to do it.

I wouldn't call confirming an e-mail address airtight.  I can have an
unlimited number of e-mail addresses at several domains.  Checking for a
unique IP would lockout any other users that use the same proxy (for
example all AOL users go through a proxy) or firewall or happen to end up
with the same dynamic IP.  Just about any other method might lock out
potential users or could be easily forged with a simple Perl script.

Although, repeated entries in a short period of time with same IP and
everything else being equal may be a sign of forged entries.

>> Hello,
>>
>> I'm creating a form that is basically a voting ballot. I'd like to know
>> if there is an airtight way of preventing users from voting more than
>> once.
>>
>> --
>> Thanks! :)
>>
>> PS: to the idiot who thinks I'm doing my homework: don't reply to this
>> idiot!
>>
>> Sent via Deja.com http://www.deja.com/
>> Before you buy.
>
>--
>
>Best Regards,
>David Tsai
>CGI Paradise
>http://www.web-consult.com/scripts/
>
>


-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: 02 Aug 2000 03:32:13 +0300
From: Eyal Ben-David <eyalb@aks.com>
Subject: Re: Configure Win32::ODBC Connection to a SQL Server?
Message-Id: <m266pkqz8y.fsf@localhost.localdomain>

"Carola Begemann" <cbegemann@orga.com> writes:

> Hallo,
> I am trying to configure a new Connection to a database on a sql 7 server
> using the Win32::ODBC module.
> Can someone help me with the correct Attrbutes for the driver "SQL Server"?
> I can nor imagine how to correct  the string
>  Win32::ODBC::ConfigDSN(ODBC_ADD_SYS_DSN,"SQL Server",
>     ( "DSN=$dsn","Description= $condb automatisch generiert",
>     "Server=$server","Database=$condb", "UID=$user", "PWD=$passwd"))
> 
> I get the error : No such file or directory (whatever that stands for).
> And if i try the GetDSN() command on an existing SQL server connection all I
> get back is a string showing the path to the driver DLL.
> I did manage to configure a new ODBC Connection to an Access
> database following the given example.
> 
>     Carola

Hello,

Create a data source with the ODBC administrator program.
Then look at HKEY_LOCAL_MACHINE\Software\ODBC\DSN_Name
You can set the values under this key as the attributes for
ConfigDSN function.

Eyal.


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

Date: Tue, 1 Aug 2000 15:40:47 -0700
From: "Chuck Odle" <chucko@purewaterstores.com>
Subject: Re: Convert 1000000 --> 1.000.000
Message-Id: <QjIh5.100$MH3.3804@news.inreach.com>


$num = 1234567;
$num =~ s/(\d)(\d{3})(\d{3})/$1\.$2\.$3/;

"Gibson" <gibson70@libero.it> wrote in message
news:ilch5.43978$wS2.368313@news.infostrada.it...
> I have just a little experience in Perl Programming
>
> How can i convert a string like this
>
> 1245789
>
> in this one
>
> 1.245.789
>
> ?
>
> TIA
>
>
>




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

Date: Wed, 02 Aug 2000 00:47:19 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: Copy a hash and const?
Message-Id: <8m7k0h$79i$10$1@news.t-online.com>

In article <8m7dip$etk$1@nnrp1.deja.com>, Brian Lavender
<blavender@spk.usace.army.mil> wrote:

> I have the following code which has a subroutine that works on a hash
> that is passed to it. I first tried passing the hash to the sub
> key_remove, but that would not work, so I tried passing a reference. I
> discovered though, that if I modified the hash in the subroutine, that
> it modified the original hash in main. I would like to make a copy of
> this hash, and leave the original hash in main untouched.

Hi Brian, 
you can use the local operator to save a previous global
variable.


 Have a look at a simple example:


$number = 20;  # a global variable
do{
   local $number = 40; print "The local value of variable numer is now
   $number\n";
};

print "Back in main and the value of number is still $number\n";

You may replace the do-block with a function but this won't change the
effect of local.
This should work with hashes either. 

Greetings, Dietmar


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

Date: Wed, 02 Aug 2000 01:00:38 -0500
From: "Dietmar Staab" <dietmar.staab@t-online.de>
Subject: Re: Copy a hash and const?
Message-Id: <8m7kpf$p9t$15$1@news.t-online.com>

In article <8m7k0h$79i$10$1@news.t-online.com>, "Dietmar Staab"
<dietmar.staab@t-online.de> wrote:

> In article <8m7dip$etk$1@nnrp1.deja.com>, Brian Lavender
> <blavender@spk.usace.army.mil> wrote:
> 
>> I have the following code which has a subroutine that works on a hash
>> that is passed to it. I first tried passing the hash to the sub
>> key_remove, but that would not work, so I tried passing a reference. I
>> discovered though, that if I modified the hash in the subroutine, that
>> it modified the original hash in main. I would like to make a copy of
>> this hash, and leave the original hash in main untouched.
> 
Hi Brian,  
here are the changes to your example: voila

------------ code ---------------
my %foo = ('father','barney','mother','betty','child','pebbles');

print "The beginning\n\n";

foreach (keys %foo) {
  print "Key: $_ Value: $foo{$_}\n";
}

print "Call key_remove which prints family except the child \n\n";

key_remove(%foo);                       <----- reference removed

print "\n Back in Main\n"; print "Is pebbles gone?\n\n";

foreach (keys %foo) {
  print "Key: $_ Value: $foo{$_}\n";
}

sub key_remove {
  # Can I make $family so it stays constant?
  local %family = shift;               <---------------- use local
  # Make a copy of %$family
  # Is this good?
  #my %cp_family = %$family;  <----- not necessary

  delete $family{'child'};              <----- use local variable in the
  next lines foreach (keys %family) {
    print "Sub Key: $_ Value: %family{$_}\n";
  }
  return (0);
}


------------ snip ----------------

it delivers the same result as your solution. 

Try it - pebbles isn't gone ;-)

Greetings, Dietmar


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

Date: Tue, 1 Aug 2000 16:25:19 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Copy a hash and const?
Message-Id: <MPG.13f0fc3973b82d3898ac20@nntp.hpl.hp.com>

In article <8m7kpf$p9t$15$1@news.t-online.com> on Wed, 02 Aug 2000 
01:00:38 -0500, Dietmar Staab <dietmar.staab@t-online.de> says...

 ...

> sub key_remove {
>   # Can I make $family so it stays constant?
>   local %family = shift;               <---------------- use local
>   # Make a copy of %$family
>   # Is this good?
>   #my %cp_family = %$family;  <----- not necessary
> 
>   delete $family{'child'};              <----- use local variable in the
>   next lines foreach (keys %family) {
>     print "Sub Key: $_ Value: %family{$_}\n";
>   }
>   return (0);
> }
> 
> 
> ------------ snip ----------------
> 
> it delivers the same result as your solution. 

It is quatsch!  Even fixing the syntax errors introduced by the pseudo-
comments, and replacing 'local' by 'my' -- see perlfaq7: "What's the 
difference between dynamic and lexical (static) scoping? Between local() 
and my()?" doesn't help.

> Try it - pebbles isn't gone ;-)

YOU try it.  Next time, try it *before* posting it.

The '-w' flag will show you where you have gone astray, and the 
nonsensical printout from that subroutine will confirm it.  (%family{$_} 
is not how you interpolate the value of a hash member into a string!)

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


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

Date: Tue, 1 Aug 2000 16:27:10 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Copy a hash and const?
Message-Id: <MPG.13f0fca51ba6137598ac21@nntp.hpl.hp.com>

In article <8m7k0h$79i$10$1@news.t-online.com> on Wed, 02 Aug 2000 
00:47:19 -0500, Dietmar Staab <dietmar.staab@t-online.de> says...

 ...

> you can use the local operator to save a previous global
> variable.

You can, but you shouldn't (unless the global variable is a Perl special 
variable).

>  Have a look at a simple example:
> 
> 
> $number = 20;  # a global variable
> do{
>    local $number = 40; print "The local value of variable numer is now
>    $number\n";
> };
> 
> print "Back in main and the value of number is still $number\n";
> 
> You may replace the do-block with a function but this won't change the
> effect of local.

perlfaq7: "What's the difference between dynamic and lexical (static) 
scoping? Between local() and my()?"

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


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

Date: Wed, 2 Aug 2000 01:00:47 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Detecting end of HTTP reply
Message-Id: <slrn8oeslr.fkd.efflandt@efflandt.xnet.com>

On Tue, 01 Aug 2000 20:17:49 +0100, Tim Cockle <T.Cockle@staffs.ac.uk> wrote:
>Hi,
>
>I am writing a simple proxy.
>
>But I don't seam to be able to detect the end of a HTTP reply.
>
>All the examples I have looked at say to use:
>while (<$server>)...
>To continue to read until the end... But this does not seam to work!
>All that happens is that the proxy continues to try and read until the
>server kills the connection.

Try:  while (defined(<$server>))

Works for me.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/



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

Date: Tue, 1 Aug 2000 18:24:10 -0500
From: "Hugh Brian" <hugh.brian@uengineer.com>
Subject: Re: dialing from another computer
Message-Id: <soen09qfdbm101@corp.supernews.com>

I want to use a perl script to do this.

--

Hugh Brian | hugh.brian@uengineer.com | http://www.uengineer.com


Logan Shaw <logan@cs.utexas.edu> wrote in message
news:8m708j$b1s$1@provolone.cs.utexas.edu...
> In article <soda30fcdbm173@corp.supernews.com>,
> Hugh Brian <hugh.brian@uengineer.com> wrote:
> >I have my two computers networked together at home. Windows internet
> >connection sharing for some reason is always dialing even when I don't
have
> >any running programs that require a connection to the internet. So I
disable
> >the automatice dialing by selecting "Never Dial a Connection" in the
> >Connection tab of Internet properties.
> >
> >What command (eg. `??????.exe`) do I need to issue from the computer that
> >has no modem to the computer that has the modem to make the modem dial
out
> >to my isp? I hope I have explained myself.
>
> Don't you comp.lang.perl.misc is kind of a strange
> place to ask this question?  It doesn't really
> seem to have anything at all to do with perl.
>
>   - Logan




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

Date: Tue, 01 Aug 2000 16:46:43 -0600
From: Ken Hare <kenhare@ultrapresence.com>
Subject: Re: Dynamic String to hash
Message-Id: <010820001646436540%kenhare@ultrapresence.com>

Hello,

> Clean it up as much as you can, test it, then post the part(s) (brief)
> you're having trouble with.
> 
> -- Jim

Here is the code parts that are killing me (and a bit more).
Once again thanks for taking the time to help. :-)
I am going to keep trying but it seems to me that everything that I
look at now just complicates things more. This usually is a sign of
trouble! I would appreciate any general pointers or even some commented
pseudo code to get me rolling in the right direction. I'm sure that
there is a simple method of approaching this. I keep thinking that
database type programs would be a great source of inspirational
examples but those that I have examined use syntax that I have trouble
with so I gain nothing but further confusion.

#make some simple changes to the input string. May not be needed with a
hash solution
#The input string can ve varying lengths but the first part will always
contain at least the following:
#Qty, SKU, Name, NoTax, Price
        if ($name eq 'GridData') {
         $Cx="::";
         $Rx="|";
         $value =~ s/Qty/Q/;
         $value =~ s/SKU/C/;
         $value =~ s/Name/D/;
         $value =~ s/NoTax/F/;
         $value =~ s/Price/P/;
         $value =~ s/\xff/$Rx/g;#
         $value =~ s/\xfe/$Cx/g; #
         
         @prods=split(/\|/,$value); #breaks up the product string into
each product
         $ROWS=scalar(@prods);   #how many products
         $COLS=scalar($product_parts[0]); #how many fields
         
         @field_names = split(/$Cx/,$prods[0];);#grab the field names

         shift @prods; #Get rid of the field names from the input string
         
         %prod_hash = map { $_, 1 } @field_names; #initialize the hash
         
         foreach $unique_product(@prods) { # this is where I am getting
confused
            
            # get the next item in the input string and break it up
into an array at the second delimiter
            @prod_details = split(/$Cx/,$shift @prods);
            
               foreach $KeyValue (keys(%prod_hash)) { 
               #############
               #here is where I need some help.
               #What I am expecting to do here is make a list with the
product info.
            #The format is
%prod_hash{"Key"]=[Product_Key_1,Product_Key_2,Product_Key_endofproducts]

            #So in Real life I will have something that is like
            #Where Q is quantity
            #%prod_hash{'Q']=['1','3','2','1','1','23']
            #The key has to correspond to the relative item in each
product string.
               
               } #ends the for foreach $KeyValue ....
         
            } #ends the foreach $unique_product(@prods)
            
            #So now I want to take the hash which I hope will look
something like this (assuming 3 products are ordered)
            # This is just to try to illustrate the data structure as I
think it should be in a %hash (table)
            # Q 1 1 2 
            # C P2 P1 P8 
            # D toy ball hat
            # F 1 1 1
            # P 3.00 4.00 8.50
            # color null red brown
            # size null null Large
               
            # the last two fields are considered extra and are to be
combined with the "D" field (description)
            
            # I haven't even started trying to build this part since I
am having such a difficult time
            # organizing the input.
            # What I want to do is create a string with the format
(using the info from the example above)
            # P::Q::C::D::F|3.00::1::P2::toy::{GST}|4.00::1::P1::ball
red::{GST}|8.50::2::P8::hat brown Large::{GST}
            # You can see how the order of the fields has changed
(important) and the color and size field is added to
            # the "D" Field (description)
             
            #This little bit of code is what I was using before I
realized that I would need to do something different
            #due to the amorphous nature of the input string
             
             #foreach $morsel(@prods) {
                #($Q, $C, $D, $F,$P) = split(/$Cx/,$morsel);
   
#                if ($F == 1 && ($F ne 'F')){
#                 $F="{GST}";
#                 }
#                 elsif ($F ne 'F')
#                 {$F="";
#                 }
#                 $value=$value.$P.$Cx.$Q.$Cx.$C.$Cx.$D.$Cx.$F.$Rx;       

#               }             
#               chop $value;
#                $name = 'Products';
#                $Products = $name;
#                $Products_Value= $value;
            
            #The string $Products_Value is then sent to a Credit Card
Authorizer.


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

Date: Tue, 01 Aug 2000 23:40:37 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Dynamic String to hash
Message-Id: <39875F6D.3A98BAF4@netstorm.net>

Ken Hare wrote:
> 
> Hello,
> 
> > Clean it up as much as you can, test it, then post the part(s) (brief)
> > you're having trouble with.
> >
> > -- Jim
> 
> Here is the code parts that are killing me (and a bit more).

<snip>

Sheesh ... but I can't say I can't relate.  Going back to your original
post:

> I have been trying to modify the string so that It consists of only 5
> fields with the "extra" fields being concatenated into one of the 5
> fields. What complicates this is that the field names can vary
> depending on what product is selected.
> 
> I know that I will need: Qty, SKU, Name, NoTax and Price with all of
> the other fields added in any order to the end of Name.
> 

Something like this might do what you want.  There are other ways.

$_ =
'QtyPartNoSKUNameWgtColorSizeoption1Option2CustomNoTaxPriceTotal1PN1SKU1Classic
Teddy Bear1Greensoption1option20$9.00$9.00130987Scary
Doll0$35.00$35.00';

$always = 'Qty SKU NoTax Price';  # always need these; treat Name
separately
@elems = split //;

$i = 0;
for (split //, shift @elems) {    # split header, build (id=>index)
hashes
	if ($always =~ /$_/) {     # 'fixed' because always need these
		$always{$_} = $i;  # this is where it's located in the record
	}
	elsif ($_ eq 'Name') {
		$Name = $i;	  # scalar; treat separately
	}
	else {
		$other{$_} = $i;  # whatever else:  (id=>index) hash
	}
	++$i;
}

# create a hash of arrays (key,value) = (id,details) for 0..n
for (@elems) {                      # header is gone, now it's the data
	@tmp = split //;
	for $f (keys %always) {     # push data for Qty, SKU, NoTax, Price
		push @ { $order{$f} }, $tmp[$always{$f}];
	}
	$name = 'Name=' . $tmp[$Name];  # item name
	for $oth (keys %other) {   # tack on in web query format &key=value
		$name .= '&' . $oth . '=' . $tmp[$other{$oth}];
	}
	push @ { $order{Name} } , $name; # push the whole deal
}

%order is now a hash of Qty SKU NoTax Price Name (rows) each with an
array of order components (columns) 0..n.  You can split the Name data
on & and = to get individual details in Name for further processing.

-- Jim


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

Date: Tue, 1 Aug 2000 22:52:33 +0200
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Re: How to use "touch" in perl
Message-Id: <1eelu1m.5v1voj1r1mri8N%otto.wyss@bluewin.ch>

> > : I'd like to set the modification time of files to the value of a
> > : reference file. While in a shell I could use touch, i.e.
> > : 
> > :         touch -r foo bar
> > : 
> If each of the files already exists, then the utime() function is better
> than going to an external command.  You also need the times of the 
> reference file in epoch seconds (as returned by stat()).
> 
> perldoc -f utime
> perldoc -f stat
>
Thanks the utime is just what I needed. I'm just trying to figure out
how I could have come to that solution myself.

O. Wyss


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

Date: Tue, 1 Aug 2000 15:47:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to use "touch" in perl
Message-Id: <MPG.13f0f36a1eda6dc998ac1e@nntp.hpl.hp.com>

In article <1eelu1m.5v1voj1r1mri8N%otto.wyss@bluewin.ch> on Tue, 1 Aug 
2000 22:52:33 +0200, Otto Wyss <otto.wyss@bluewin.ch> says...
> > > : I'd like to set the modification time of files to the value of a
> > > : reference file. While in a shell I could use touch, i.e.
> > > : 
> > > :         touch -r foo bar
> > > : 
> > If each of the files already exists, then the utime() function is better
> > than going to an external command.  You also need the times of the 
> > reference file in epoch seconds (as returned by stat()).
> > 
> > perldoc -f utime
> > perldoc -f stat
> >
> Thanks the utime is just what I needed. I'm just trying to figure out
> how I could have come to that solution myself.

Using Unix:

% perldoc perlfunc | grep touch
    This code has the same effect as the "touch" command if the
%

Similarly, for Windows, use your browser to search the perlfunc.html web 
page for 'touch'.

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


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

Date: Tue, 1 Aug 2000 23:07:35 +0100
From: "Phil Latio" <globalcon2@myhouse.com>
Subject: Re: I have an idea but will it work ?
Message-Id: <8m7hii$n26$1@uranium.btinternet.com>


Drew Simonis <care227@attglobal.net> wrote in message
news:39872179.7CBA6570@attglobal.net...
> Michael Carman wrote:
> >
> >
> > Sure, but I wouldn't do it by searching the file -- that would get messy
> > and tend to obfuscate the logic. I'd read the file into a hash, and then
> > do your lookups that way.
> >
>
> What if the OP has too much data to read into the hash?
> I see a better option as a tied hash, but even better is
> using a DBI module to search against the file via SQL queries.
>
> If the combinations can get very complicated, perhaps a real
> database is in order.

Many thanks for both replies.

I have seen this DBI module mentioned on other posts but wouldn't I need a
telnet or command line account for DBI ?  I have a CGI-Bin, SSI, Sendmail,
Perl and PHP but I don't think he trusts me any further.

However I did manage to wangle a MySQL account yesterday with a database
already set-up. I suppose it's up to me populate it with tables and fields.

I will have a look at this DBI module now and see where I go from there.

Again many thanks for taking the time to help.









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

Date: Tue, 1 Aug 2000 23:31:16 +0100
From: "Phil Latio" <globalcon2@myhouse.com>
Subject: Re: I have an idea but will it work ?
Message-Id: <8m7iv6$oot$1@uranium.btinternet.com>


Michael Carman <mjcarman@home.com> wrote in message
news:39871656.1B7ED0C@home.com...
> Phil Latio wrote:
> >
> > I would now like to display the price of the printing job dynamically.
> >
> > Could I create a 5 field flat file database something like below
> > with a line per record and then have a perl script that would search
> > the database on the first 4 fields from the values entered by the
> > customer (look up feature?) and drop in the price automatically.
> >
> > COLOUR,WEIGHT,SIDED,QUANTITY,PRICE
> > white, 80gsm, s/sided, 1000, 40.00
> > white, 80gsm, s/sided, 2500, 75.00
> > etc
> > etc
>
> Sure, but I wouldn't do it by searching the file -- that would get messy
> and tend to obfuscate the logic. I'd read the file into a hash, and then
> do your lookups that way.
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my %print_cost;
>
> while (<DATA>) {
>     chomp;
>     my ($color, $weight, $sided, $quantity, $price) = split;
>     $print_cost{$color}{$weight}{$sided}{$quantity} = $price;
> }
>
> # This data would come from your form
> my $number = 1000;
> my $weight = '80gsm';
> my $sides  = 's/sided';
> my $color  = 'white';
>
> # And spit out the price
> printf("The price for %d %s, %s, %s prints is %s.\n",
>     $number, $color, $weight, $sides,
>     $print_cost{$color}{$weight}{$sides}{$number});
>
> __DATA__
> white 80gsm s/sided 1000 40.00
> white 80gsm s/sided 2500 75.00
>
> You'll want to consider other things, like what if the user wants 1004
> copies? (if that's an option). Also, if the number of possible
> combinations is truly large, creating that file would be a pain. (Are
> 1000 copies on blue paper going to cost something different than they do
> on green paper? What happens when supply costs go up and you need to
> change every entry to compensate?)
>
> Perhaps some sort of formula would be better? e.g. 80gsm paper costs 5
> pence/copy, color is 1 pence/copy extra, double-sided copies cost 1.3
> times single-sided, 2500+ copies get a 15% discount, etc... You probably
> already have a formula like this that you use to come up with your
> pricing. Why not use it directly?
>
> -mjc

Many thanks for this reply too.

I think your piece of code is an excellent starting point for me to develop
something more complicated later.

I already have all the prices in a MS Excel spreadsheet and you are correct
to assume that each is based on an exact consistant calculation. Luckilly I
only offer 5 order quantities being 1000, 2500, 5000, 10000 and 25000 which
I will put into a drop down list.

I am interested to know how long you have been programming with Perl as you
seem to have come up with that little script very quickly. I have a number
of ideas for websites but have very little programming experience so I am
considering learning Perl. Do you have any suggestions to online documention
for beginners ?





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

Date: Wed, 2 Aug 2000 09:36:20 +1000
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: Net::FTP Module
Message-Id: <vbJh5.63894$N4.1848234@ozemail.com.au>


Hello there..I have a question in regards to using this module

I have been thru the man pages and cannot find a chmod function in the
module. Is there any other way i can chmod files when loggin into someones
account using the module?

Also another thing with this module. It seems to work file when you upload
one file at a time. But if i try and upload more than one file using the
same filehandle (don't know if thats the correct termonology) the only file
which gets uploaded is the first one. However...if i close the filehandle
and reopen it in a loop it works fine..but alas thats very inefficient, and
it clogs up the log files..anyone have a solution?

here is a snippet of code which i'm using atm

#!/usr/bin/perl

use Net::FTP;
use Net::Cmd;

foreach (@filelisting) {
    # IF I TAKE THE CREATION OF $FTP out of the loop it doesn't copy the
rest of the files
    my $ftp = Net::FTP->new("$server");
    my $logsuccess=$ftp->login("$username","$password");
    $ftp->cwd($movepath);
    $ftp->binary();
    $ftp->put("$tempdir/$_");
    $ftp->quit;
    `rm -f $tempdir/$_`;
  }
--
----------------------------------------------------------------------------
----------------
Troy Rasiah
Database/Web Developer
Vicnet
troyr@vicnet.net.au
----------------------------------------------------------------------------
----------------




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

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


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