[16178] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3590 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 18:28:49 2000

Date: Mon, 10 Jul 2000 15:28:32 -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: <963268112-v9-i3590@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Jul 2000     Volume: 9 Number: 3590

Today's topics:
        perl cookie <gold@kr8.com>
    Re: perl cookie <care227@attglobal.net>
    Re: perl cookie <gold@kr8.com>
    Re: perl cookie (NP)
    Re: perl cookie <care227@attglobal.net>
    Re: perl cookie johngold37@my-deja.com
    Re: perl cookie <gold@kr8.com>
        Perl Directory Structure <jmwjr@bellsouh.net>
    Re: Perl Directory Structure <nnickee@nnickee.com>
    Re: Perl Directory Structure (Bart Lateur)
        Perl filtering in INN, and panic: top_env <dickon.hood@bbc.co.uk>
        Perl for Win32 Question (Pete Holsberg)
    Re: Perl for Win32 Question <lauren_smith13@hotmail.com>
    Re: Perl for Win32 Question <tina@streetmail.com>
    Re: Perl for Win32 Question <care227@attglobal.net>
    Re: Perl for Win32 Question billmez@my-deja.com
        perl glob command and "dos" window <jennifer.m.lill_no_spam@lexis-nexis.com>
    Re: perl glob command and "dos" window (Eric Bohlman)
    Re: perl glob command and "dos" window <shcorey@nortelnetworks.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 8 Jul 2000 18:21:47 +0100
From: "John Gold" <gold@kr8.com>
Subject: perl cookie
Message-Id: <8k7lac$e4a$1@duke.telepac.pt>

Hi,
has anybody had experience programming cookies, I am trying to store
personalised client info in a hash data structure within a cookie, however
when I retrieve the hash from the cookie and append new client data with the
existing data from the hash and try to refresh the cookie I recieve a server
error. I am currently redirecting my cookie to a location as well as
refreshing the cookie at the same time but still have problems, here is the
code, can anybody tell me if there is a problem with my method or
implementation,

thanks,

vick


#! /usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp  qw(fatalsToBrowser);
use diagnostics;
use strict;



  my $inputs = get_inputs();
  define_action($inputs);




sub get_inputs() {
  my @names;
  my %form_inputs;
  my ($key, $val);

  @names = param();
    foreach $key (@names) {
      $val = param($key);
      %form_inputs = (%form_inputs, $key, $val);
   }

  $form_inputs{cookie} = cookie("shopping");
  $form_inputs{display_address} = "../product_files/display_page.html";

  $inputs = \%form_inputs;
  return $inputs;
}




# DEFINE ACTION:


sub define_action($) {
  my ($inputs) = @_;


  if ($inputs->{display_products} ne "") {
    display_products($inputs);
   } elsif ($inputs->{add} ne "") {
      add_product($inputs);
     } elsif ($inputs->{refresh} ne "") {
       display_chosen_products($inputs);
      } elsif ($inputs->{total} ne "") {
        total_of_products($inputs);
        } elsif ($inputs->{delete} ne "") {
           delete_a_product();
          } else {
            order_product();
            }
}




sub get_dbh() {
  use DBI;

  my $dbname = "****";
  my $dbowner = "*****";
  my $dbpassword = "****";
  my $dbh;

  $dbh = DBI->connect( $dbname, $dbowner, $dbpassword, "mysql") or die
"cannot connect to the db: $DBI::errstr";
  return $dbh;
}





# ADD PRODUCT TO SHOPPING CART:


sub add_product($) {
  my ($inputs) = @_;
  my ($key, $val);
  my (%shop, %products);
  my $no;

  %shop = cookie("shopping");


   if (%shop) {
     $shop{rand_key} = srand( time() ^ ($$ + ($$ << 15)) );
   }

  while (($key, $val) = each(%$inputs)) {
   next unless $key =~ /[0-9]/;
   next if $val eq "";
   next if $val == 0;
   %products = (%products, $key, $val);
   }

  if (%products)

   %shop = (%shop, %products);
    delete $shop{""};
  } else {
     print "content-type: text/html \n\n";
     print "You did not select any items. Please insert a number of items in
quantity box if you would like to purchase an item";
     exit;
    }


   display_chosen_products($inputs, %shop);

}






# DISPLAY CHOSEN PRODUCTS:

sub display_chosen_products() {
  my ($inputs, %shop) = @_;
  my ($dbh, $sql, $sth);
  my ($product, $array_ref, $row);
  my ($id_ref, $product_name, $price, $quantity, $total);
  my  @keys;
  my ($key,$val);
  my $refresh_cookie;

  $inputs->{temp_file} = "../htdocs/shopping/temp_file"  . $shop{rand_key} .
".html";
  $inputs->{shop_file} = "../htdocs/shopping/shop_file" . $shop{rand_key} .
".html";
  $inputs->{old_file} = "../htdocs/shopping/old_file" . $shop{rand_key} .
".html";
  $inputs->{web_address} = "../shopping/shop_file" . $shop{rand_key} .
".html";



  @keys = sort { $a <=> $b } keys(%shop);


  $dbh = get_dbh();

  $sql = "SELECT ID_REF, PRODUCT_NAME, PRICE FROM products WHERE ID_REF IN
 ";


  for $product (@keys) {
  next if $product eq "rand_key";
  $sql .= "$product," ;
  }

  $sql =~ s/,$//;
  $sql .= ") ORDER BY ID_REF";

  $sth = $dbh->prepare($sql) or die "cannot prepare product_sql:
$DBI::errstr";
  $sth->execute() or die "cannot execute product sth: $DBI::errstr";

  $array_ref = $sth->fetchall_arrayref();

  open (TEMP, ">$inputs->{temp_file}") or die "cannot open temp_file: $!";
  print TEMP <<EOF;

  <HTML>
  <HEAD>
  <TITLE>Chosen Products</TITLE>
  </HEAD>

  <BODY>
  <FORM action="../cgi-local/web_shop.cgi"  method="post">

  <TABLE align="center" width="60%">
  <TR>
  <TD colspan="5" align="center"><H2>WWC_SHOP</H2></TD>
  </TR>
  <TR>
  <TD><BR></TD>
  </TR>
  <TR>
  <TD bgcolor="gray">DELETE</TD>
  <TD bgcolor="gray">QTY</TD>
  <TD bgcolor="gray">PRODUCT</TD>
  <TD bgcolor="gray">PRICE</TD>
  <TD bgcolor="gray">TOTAL</TD>
  </TR>
EOF


      for $row (@$array_ref)

         ($id_ref,$product_name, $price) = @$row;
          $quantity = $shop{$id_ref};
          $total = $price * $quantity;


  print TEMP <<EOF;
  <TR>
  <TD><input type="submit" name="delete" value="D"></TD>
  <TD>$quantity</TD>
  <TD>$product_name </TD>
  <TD>$price</TD>
  <TD>$total</TD>
  </TR>
EOF
     }

  print TEMP <<EOF;
  </TABLE>
  </FORM>
  </BODY>
  </HTML>
EOF
  close (TEMP);

  open (SHOP, $inputs->{shop_file}) or die "cannot open shop_file: $!";
  rename ($inputs->{shop_file}, "$inputs->{old_file}");
  rename ($inputs->{temp_file}, $inputs->{shop_file}) or die "cannot rename
temp to shop: $!";
#  unlink $inputs->{old_file}; #or die "cannot unlink temp_file: $!";



  $refresh_cookie =   cookie ( -name => "shopping",
                                 -value => \%shop  );
 print "Location: $inputs->{web_address}\n\n";

 print redirect( -url => $inputs->{web_address},
                   -cookie => $refresh_cookie );
 exit;

  }




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

Date: Sat, 08 Jul 2000 13:48:12 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: perl cookie
Message-Id: <3967695C.9682B72D@attglobal.net>

John Gold wrote:
> 
> Hi,
> has anybody had experience programming cookies, 

Perl doesn't have cookies.

> I am trying to store
> personalised client info in a hash data structure within a cookie, however
> when I retrieve the hash from the cookie and append new client data with the
> existing data from the hash and try to refresh the cookie I recieve a server
> error. 

Perl doesn't know what a server is.  Sounds like you have a CGI 
problem.  Try comp.infosystems.www.authoring.cgi


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

Date: Sat, 8 Jul 2000 19:58:12 +0100
From: "John Gold" <gold@kr8.com>
Subject: Re: perl cookie
Message-Id: <8k7qua$ole$1@duke.telepac.pt>

Hi Drew,
thanks for the usefull information, obviously all the code I have written is
make believe!

Drew Simonis wrote in message <3967695C.9682B72D@attglobal.net>...
>John Gold wrote:
>>
>> Hi,
>> has anybody had experience programming cookies,
>
>Perl doesn't have cookies.
>
>> I am trying to store
>> personalised client info in a hash data structure within a cookie,
however
>> when I retrieve the hash from the cookie and append new client data with
the
>> existing data from the hash and try to refresh the cookie I recieve a
server
>> error.
>
>Perl doesn't know what a server is.  Sounds like you have a CGI
>problem.  Try comp.infosystems.www.authoring.cgi




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

Date: Sat, 08 Jul 2000 19:40:45 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: perl cookie
Message-Id: <1tL95.318903$VR.4815400@news5.giganews.com>

On Sat, 8 Jul 2000 19:58:12 +0100, John Gold <gold@kr8.com> wrote:
:
: thanks for the usefull information, obviously all the code I have written is
: make believe!

What Drew was trying to point out (albeit in a terse and
not-so-professional manner) was that your question might be better
suited for comp.infosystems.www.authoring.cgi -- since dealing with WWW
subject matter (such as cookies) isn't specific to Perl itself.

On the other hand, if you rephrase your question, use a more specific
'Subject:' header and provide a code segment -- you might also get an
answer in this newsgroup.

-- 
Nate



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

Date: Sat, 08 Jul 2000 16:11:17 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: perl cookie
Message-Id: <39678AE5.7BB5E2E7@attglobal.net>

[posted and Cc'd]

John Gold wrote:
> 
> Hi Drew,
> thanks for the usefull information, obviously all the code I have written is
> make believe!


You didn't say you had a Perl problem. You said you got a server error 
when running from a web page.  You also negelected to:

a) specify what that error was (an extract from the error log will help)
b) tell how it went from the command line

Either of the above could have indicated more closley if this question
was on topic or not.  Without the information, the only assumption is 
that it is not.  CGI questions have their own newsgroup for a reason.  
The probelms are generally language independant.

Looking at your code, I am assuming that you got an error 500.
Since you have wisely used Carp, we know it isn't from a script
problem, per se.  You've properly used all the right tools (-w, strict)
but you did forget one thing.  Look:

> if (%products)
> 
>    %shop = (%shop, %products);
>     delete $shop{""};
>   } else {
>      print "content-type: text/html \n\n"; 
>      print "You did not select any items. Please insert a number of items in
> quantity box if you would like to purchase an item";
>      exit;
>     }

The above code snipet is the only place you ever output a valid header,
and thats to cover an error condition.  Your normal output seems to 
omits the header, which is why (I'd bet on it) you are seeing an error 
500.  Following either A or B from above would have revealed this
problem
to you quite quickly.  This is also in every CGI faq I've ever read.


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

Date: Sat, 08 Jul 2000 23:10:39 GMT
From: johngold37@my-deja.com
Subject: Re: perl cookie
Message-Id: <8k8cd9$tqv$1@nnrp1.deja.com>

Hi Drew,
thanks for your comments, (point taken with regards to description of
the problem) however if I do put another valid header in the script
the  "redirect" address and cookie header are printed to the browser
and the redirect address is not located. Initially my program would
retrieve clients chosen items and then display their items dynamically
to the browser on the fly (instead of printing customer orders to temp.
files). However I found that the cookie again would be printed to the
browser window with  the dynamic display of the  customer selections on
the fly  when refreshing the cookie - this i believe is due to
the "content-type: text/html \n\n" header forcing the cookie header to
the browser window instead of to the clients hard drive.

My question is how do i refresh a cookie with new values as well as
dynamically creating  new customer "shop items" for display on the fly
without receiving the cookie displayed on the browser window.

Any more suggestions would be greatly appreciated. Thanks!!!



#! /usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp  qw(fatalsToBrowser);
use diagnostics;
use strict;



  my $inputs = get_inputs();
  define_action($inputs);




sub get_inputs() {
  my @names;
  my %form_inputs;
  my ($key, $val);

  @names = param();
    foreach $key (@names) {
      $val = param($key);
      %form_inputs = (%form_inputs, $key, $val);
   }

  $form_inputs{cookie} = cookie("shopping");
  $form_inputs{display_address} = "../product_files/display_page.html";

  $inputs = \%form_inputs;
  return $inputs;
}




# DEFINE ACTION:


sub define_action($) {
  my ($inputs) = @_;


  if ($inputs->{display_products} ne "") {
    display_products($inputs);
   } elsif ($inputs->{add} ne "") {
      add_product($inputs);
     } elsif ($inputs->{refresh} ne "") {
       display_chosen_products($inputs);
      } elsif ($inputs->{total} ne "") {
        total_of_products($inputs);
        } elsif ($inputs->{delete} ne "") {
           delete_a_product();
          } else {
            order_product();
            }
}




sub get_dbh() {
  use DBI;

  my $dbname = "****";
  my $dbowner = "*****";
  my $dbpassword = "****";
  my $dbh;

  $dbh = DBI->connect( $dbname, $dbowner, $dbpassword, "mysql") or die
"cannot connect to the db: $DBI::errstr";
  return $dbh;
}





# ADD PRODUCT TO SHOPPING CART:


sub add_product($) {
  my ($inputs) = @_;
  my ($key, $val);
  my (%shop, %products);
  my $no;

  %shop = cookie("shopping");


   if (%shop) {
     $shop{rand_key} = srand( time() ^ ($$ + ($$ << 15)) );
   }

  while (($key, $val) = each(%$inputs)) {
   next unless $key =~ /[0-9]/;
   next if $val eq "";
   next if $val == 0;
   %products = (%products, $key, $val);
   }

  if (%products)

   %shop = (%shop, %products);
    delete $shop{""};
  } else {
     print "content-type: text/html \n\n";
     print "You did not select any items. Please insert a number of
items in
quantity box if you would like to purchase an item";
     exit;
    }


   display_chosen_products($inputs, %shop);

}






# DISPLAY CHOSEN PRODUCTS:

sub display_chosen_products() {
  my ($inputs, %shop) = @_;
  my ($dbh, $sql, $sth);
  my ($product, $array_ref, $row);
  my ($id_ref, $product_name, $price, $quantity, $total);
  my  @keys;
  my ($key,$val);
  my $refresh_cookie;

  $inputs->{temp_file} = "../htdocs/shopping/temp_file"  . $shop
{rand_key} .
".html";
  $inputs->{shop_file} = "../htdocs/shopping/shop_file" . $shop
{rand_key} .
".html";
  $inputs->{old_file} = "../htdocs/shopping/old_file" . $shop
{rand_key} .
".html";
  $inputs->{web_address} = "../shopping/shop_file" . $shop{rand_key} .
".html";



  @keys =  keys(%shop);


  $dbh = get_dbh();

  $sql = "SELECT ID_REF, PRODUCT_NAME, PRICE FROM products WHERE ID_REF
IN
";


  for $product (@keys) {
  next if $product eq "rand_key";
  $sql .= "$product," ;
  }

  $sql =~ s/,$//;
  $sql .= ") ORDER BY ID_REF";

  $sth = $dbh->prepare($sql) or die "cannot prepare product_sql:
$DBI::errstr";
  $sth->execute() or die "cannot execute product sth: $DBI::errstr";

  $array_ref = $sth->fetchall_arrayref();

  open (TEMP, ">$inputs->{temp_file}") or die "cannot open temp_file:
$!";
  print TEMP <<EOF;

  <HTML>
  <HEAD>
  <TITLE>Chosen Products</TITLE>
  </HEAD>

  <BODY>
  <FORM action="../cgi-local/web_shop.cgi"  method="post">

  <TABLE align="center" width="60%">
  <TR>
  <TD colspan="5" align="center"><H2>WWC_SHOP</H2></TD>
  </TR>
  <TR>
  <TD><BR></TD>
  </TR>
  <TR>
  <TD bgcolor="gray">DELETE</TD>
  <TD bgcolor="gray">QTY</TD>
  <TD bgcolor="gray">PRODUCT</TD>
  <TD bgcolor="gray">PRICE</TD>
  <TD bgcolor="gray">TOTAL</TD>
  </TR>
EOF


      for $row (@$array_ref)

         ($id_ref,$product_name, $price) = @$row;
          $quantity = $shop{$id_ref};
          $total = $price * $quantity;


  print TEMP <<EOF;
  <TR>
  <TD><input type="submit" name="delete" value="D"></TD>
  <TD>$quantity</TD>
  <TD>$product_name </TD>
  <TD>$price</TD>
  <TD>$total</TD>
  </TR>
EOF
     }

  print TEMP <<EOF;
  </TABLE>
  </FORM>
  </BODY>
  </HTML>
EOF
  close (TEMP);

  open (SHOP, $inputs->{shop_file}) or die "cannot open shop_file: $!";
  rename ($inputs->{shop_file}, "$inputs->{old_file}");
  rename ($inputs->{temp_file}, $inputs->{shop_file}) or die "cannot
rename
temp to shop: $!";
#  unlink $inputs->{old_file}; #or die "cannot unlink temp_file: $!";



  $refresh_cookie =   cookie ( -name => "shopping",
                                 -value => \%shop  );
print "Location: $inputs->{web_address}\n\n";

print redirect( -url => $inputs->{web_address},
                   -cookie => $refresh_cookie );
exit;

  }









-----Original Message-----



From: Drew Simonis <care227@attglobal.net>
Newsgroups: comp.lang.perl.misc
Cc: gold@kr8.com <gold@kr8.com>
Date: Samstag, 8. Juli 2000 21:14
Subject: Re: perl cookie


>[posted and Cc'd]
>
>John Gold wrote:
>>
>> Hi Drew,
>> thanks for the usefull information, obviously all the code I have
written is
>> make believe!
>
>
>You didn't say you had a Perl problem. You said you got a server error
>when running from a web page.  You also negelected to:
>
>a) specify what that error was (an extract from the error log will
help)
>b) tell how it went from the command line
>
>Either of the above could have indicated more closley if this question
>was on topic or not.  Without the information, the only assumption is
>that it is not.  CGI questions have their own newsgroup for a reason.
>The probelms are generally language independant.
>
>Looking at your code, I am assuming that you got an error 500.
>Since you have wisely used Carp, we know it isn't from a script
>problem, per se.  You've properly used all the right tools (-w, strict)
>but you did forget one thing.  Look:
>
>> if (%products)
>>
>>    %shop = (%shop, %products);
>>     delete $shop{""};
>>   } else {
>>      print "content-type: text/html \n\n";
>>      print "You did not select any items. Please insert a number of
items in
>> quantity box if you would like to purchase an item";
>>      exit;
>>     }
>
>The above code snipet is the only place you ever output a valid header,
>and thats to cover an error condition.  Your normal output seems to
>omits the header, which is why (I'd bet on it) you are seeing an error
>500.  Following either A or B from above would have revealed this
>problem
>to you quite quickly.  This is also in every CGI faq I've ever read.
>
>








In article <39678AE5.7BB5E2E7@attglobal.net>,
  care227@attglobal.net wrote:
> [posted and Cc'd]
>
> John Gold wrote:
> >
> > Hi Drew,
> > thanks for the usefull information, obviously all the code I have
written is
> > make believe!
>
> You didn't say you had a Perl problem. You said you got a server
error
> when running from a web page.  You also negelected to:
>
> a) specify what that error was (an extract from the error log will
help)
> b) tell how it went from the command line
>
> Either of the above could have indicated more closley if this question
> was on topic or not.  Without the information, the only assumption is
> that it is not.  CGI questions have their own newsgroup for a
reason.
> The probelms are generally language independant.
>
> Looking at your code, I am assuming that you got an error 500.
> Since you have wisely used Carp, we know it isn't from a script
> problem, per se.  You've properly used all the right tools (-w,
strict)
> but you did forget one thing.  Look:
>
> > if (%products)
> >
> >    %shop = (%shop, %products);
> >     delete $shop{""};
> >   } else {
> >      print "content-type: text/html \n\n";
> >      print "You did not select any items. Please insert a number of
items in
> > quantity box if you would like to purchase an item";
> >      exit;
> >     }
>
> The above code snipet is the only place you ever output a valid
header,
> and thats to cover an error condition.  Your normal output seems to
> omits the header, which is why (I'd bet on it) you are seeing an
error
> 500.  Following either A or B from above would have revealed this
> problem
> to you quite quickly.  This is also in every CGI faq I've ever read.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 9 Jul 2000 11:02:07 +0100
From: "John Gold" <gold@kr8.com>
Subject: Re: perl cookie
Message-Id: <8k9ftn$tnu$1@duke.telepac.pt>

Hi Drew,
thanks for your comments, (point taken with regards to description of the
problem) however if I do put another valid header in the script  the
"redirect" address and cookie header are printed to the browser and the
redirect address is not located. Initially my program would retrieve clients
chosen items and then display their items dynamically to the browser on the
fly (instead of printing customer orders to temp. files). However I found
that the cookie again would be printed to the browser window with  the
dynamic display of the  customer selections on the fly  when refreshing the
cookie - this i believe is due to the "content-type: text/html \n\n" header
forcing the cookie header to the browser window instead of to the clients
hard drive.

My question is how do i refresh a cookie with new values as well as
dynamically creating  new customer "shop items" for display on the fly
without receiving the cookie displayed on the browser window.

Any more suggestions would be greatly appreciated. Thanks!!!



#! /usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp  qw(fatalsToBrowser);
use diagnostics;
use strict;



  my $inputs = get_inputs();
  define_action($inputs);




sub get_inputs() {
  my @names;
  my %form_inputs;
  my ($key, $val);

  @names = param();
    foreach $key (@names) {
      $val = param($key);
      %form_inputs = (%form_inputs, $key, $val);
   }

  $form_inputs{cookie} = cookie("shopping");
  $form_inputs{display_address} = "../product_files/display_page.html";

  $inputs = \%form_inputs;
  return $inputs;
}




# DEFINE ACTION:


sub define_action($) {
  my ($inputs) = @_;


  if ($inputs->{display_products} ne "") {
    display_products($inputs);
   } elsif ($inputs->{add} ne "") {
      add_product($inputs);
     } elsif ($inputs->{refresh} ne "") {
       display_chosen_products($inputs);
      } elsif ($inputs->{total} ne "") {
        total_of_products($inputs);
        } elsif ($inputs->{delete} ne "") {
           delete_a_product();
          } else {
            order_product();
            }
}




sub get_dbh() {
  use DBI;

  my $dbname = "****";
  my $dbowner = "*****";
  my $dbpassword = "****";
  my $dbh;

  $dbh = DBI->connect( $dbname, $dbowner, $dbpassword, "mysql") or die
"cannot connect to the db: $DBI::errstr";
  return $dbh;
}





# ADD PRODUCT TO SHOPPING CART:


sub add_product($) {
  my ($inputs) = @_;
  my ($key, $val);
  my (%shop, %products);
  my $no;

  %shop = cookie("shopping");


   if (%shop) {
     $shop{rand_key} = srand( time() ^ ($$ + ($$ << 15)) );
   }

  while (($key, $val) = each(%$inputs)) {
   next unless $key =~ /[0-9]/;
   next if $val eq "";
   next if $val == 0;
   %products = (%products, $key, $val);
   }

  if (%products)

   %shop = (%shop, %products);
    delete $shop{""};
  } else {
     print "content-type: text/html \n\n";
     print "You did not select any items. Please insert a number of items in
quantity box if you would like to purchase an item";
     exit;
    }


   display_chosen_products($inputs, %shop);

}






# DISPLAY CHOSEN PRODUCTS:

sub display_chosen_products() {
  my ($inputs, %shop) = @_;
  my ($dbh, $sql, $sth);
  my ($product, $array_ref, $row);
  my ($id_ref, $product_name, $price, $quantity, $total);
  my  @keys;
  my ($key,$val);
  my $refresh_cookie;

  $inputs->{temp_file} = "../htdocs/shopping/temp_file"  . $shop{rand_key} .
".html";
  $inputs->{shop_file} = "../htdocs/shopping/shop_file" . $shop{rand_key} .
".html";
  $inputs->{old_file} = "../htdocs/shopping/old_file" . $shop{rand_key} .
".html";
  $inputs->{web_address} = "../shopping/shop_file" . $shop{rand_key} .
".html";



  @keys =  keys(%shop);


  $dbh = get_dbh();

  $sql = "SELECT ID_REF, PRODUCT_NAME, PRICE FROM products WHERE ID_REF IN
";


  for $product (@keys) {
  next if $product eq "rand_key";
  $sql .= "$product," ;
  }

  $sql =~ s/,$//;
  $sql .= ") ORDER BY ID_REF";

  $sth = $dbh->prepare($sql) or die "cannot prepare product_sql:
$DBI::errstr";
  $sth->execute() or die "cannot execute product sth: $DBI::errstr";

  $array_ref = $sth->fetchall_arrayref();

  open (TEMP, ">$inputs->{temp_file}") or die "cannot open temp_file: $!";
  print TEMP <<EOF;

  <HTML>
  <HEAD>
  <TITLE>Chosen Products</TITLE>
  </HEAD>

  <BODY>
  <FORM action="../cgi-local/web_shop.cgi"  method="post">

  <TABLE align="center" width="60%">
  <TR>
  <TD colspan="5" align="center"><H2>WWC_SHOP</H2></TD>
  </TR>
  <TR>
  <TD><BR></TD>
  </TR>
  <TR>
  <TD bgcolor="gray">DELETE</TD>
  <TD bgcolor="gray">QTY</TD>
  <TD bgcolor="gray">PRODUCT</TD>
  <TD bgcolor="gray">PRICE</TD>
  <TD bgcolor="gray">TOTAL</TD>
  </TR>
EOF


      for $row (@$array_ref)

         ($id_ref,$product_name, $price) = @$row;
          $quantity = $shop{$id_ref};
          $total = $price * $quantity;


  print TEMP <<EOF;
  <TR>
  <TD><input type="submit" name="delete" value="D"></TD>
  <TD>$quantity</TD>
  <TD>$product_name </TD>
  <TD>$price</TD>
  <TD>$total</TD>
  </TR>
EOF
     }

  print TEMP <<EOF;
  </TABLE>
  </FORM>
  </BODY>
  </HTML>
EOF
  close (TEMP);

  open (SHOP, $inputs->{shop_file}) or die "cannot open shop_file: $!";
  rename ($inputs->{shop_file}, "$inputs->{old_file}");
  rename ($inputs->{temp_file}, $inputs->{shop_file}) or die "cannot rename
temp to shop: $!";
#  unlink $inputs->{old_file}; #or die "cannot unlink temp_file: $!";



  $refresh_cookie =   cookie ( -name => "shopping",
                                 -value => \%shop  );
print "Location: $inputs->{web_address}\n\n";

print redirect( -url => $inputs->{web_address},
                   -cookie => $refresh_cookie );
exit;

  }



--------------------------
NP wrote in message <1tL95.318903$VR.4815400@news5.giganews.com>...
>On Sat, 8 Jul 2000 19:58:12 +0100, John Gold <gold@kr8.com> wrote:
>:
>: thanks for the usefull information, obviously all the code I have written
is
>: make believe!
>
>What Drew was trying to point out (albeit in a terse and
>not-so-professional manner) was that your question might be better
>suited for comp.infosystems.www.authoring.cgi -- since dealing with WWW
>subject matter (such as cookies) isn't specific to Perl itself.
>
>On the other hand, if you rephrase your question, use a more specific
>'Subject:' header and provide a code segment -- you might also get an
>answer in this newsgroup.
>
>--
>Nate
>







John Gold wrote in message ...
>Hi Drew,
>thanks for the usefull information, obviously all the code I have written
is
>make believe!
>
>Drew Simonis wrote in message <3967695C.9682B72D@attglobal.net>...
>>John Gold wrote:
>>>
>>> Hi,
>>> has anybody had experience programming cookies,
>>
>>Perl doesn't have cookies.
>>
>>> I am trying to store
>>> personalised client info in a hash data structure within a cookie,
>however
>>> when I retrieve the hash from the cookie and append new client data with
>the
>>> existing data from the hash and try to refresh the cookie I recieve a
>server
>>> error.
>>
>>Perl doesn't know what a server is.  Sounds like you have a CGI
>>problem.  Try comp.infosystems.www.authoring.cgi
>
>




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

Date: Mon, 10 Jul 2000 11:05:54 -0400
From: "Mike Wilson" <jmwjr@bellsouh.net>
Subject: Perl Directory Structure
Message-Id: <lIla5.3185$fh7.35017@news2.atl>

Win2000,Activestate Perl 5.6
I have tried to install perl to C:\Program Files\Utils\Perl. The
installation works fine.
But I have noticed that when I try to install certain modules (ex.
Win32::GUI) I have
a problem with the module installation. I have also tried perl2exe and had
problems
with compiling scripts. I then reinstalled to C:\Perl and everything works
fine. The spaces
seem to cause problems. I tried messing with PATH by changing it from
`Program Files`
to `Progra~1`, and making the same change to the module install files.
Anybody noticed this? Anybody use a perl path with spaces/long filenames?
Any ideas? Thanks Mike




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

Date: Mon, 10 Jul 2000 10:55:25 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: Perl Directory Structure
Message-Id: <98291874E2E2C981.E278341B02AE57ED.EB3D8AF7D3EF2FFB@lp.airnews.net>

On Mon, 10 Jul 2000 11:05:54 -0400, someone claiming to be "Mike
Wilson" <jmwjr@bellsouh.net> said:

>Win2000,Activestate Perl 5.6
>I have tried to install perl to C:\Program Files\Utils\Perl. The
>installation works fine.
>But I have noticed that when I try to install certain modules (ex.
>Win32::GUI) I have a problem with the module installation. 
>I have also tried perl2exe and had problems with compiling scripts.

I used to occasionally have problems with perl2exe (only when certain
modules were used) but as soon as I started moving the script into my
Perl directory (not bin, just the top-level Perl directory) and
running perl2exe from there, the problems stopped.

> I then reinstalled to C:\Perl and everything works
>fine. The spaces seem to cause problems. I tried messing with PATH 
>by changing it from `Program Files` to `Progra~1`, and making the same 
>change to the module install files.
>Anybody noticed this? Anybody use a perl path with spaces/long filenames?
>Any ideas? Thanks Mike

Have you checked ActivePerl's bug tracker?
http://bugs.activestate.com/ActivePerl

I really have nothing else to add, since I didn't install to a path
with a space in the name.

Nnickee



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

Date: Mon, 10 Jul 2000 18:00:16 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Perl Directory Structure
Message-Id: <396b0eca.440114@news.skynet.be>

Mike Wilson wrote:

>I have tried to install perl to C:\Program Files\Utils\Perl. The
>installation works fine.
>But I have noticed that when I try to install certain modules (ex.
>Win32::GUI) I have
>a problem with the module installation.

>Anybody use a perl path with spaces/long filenames?

I think I've seen it mentioned in the installation notes, somewhere: do
NOT use a path with spaces in it, as a root for your Perl installation.
The long filenames by themselves aren't a problem, I guess.

-- 
	Bart.


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

Date: 4 Jul 2000 10:11:20 GMT
From: Dickon Hood <dickon.hood@bbc.co.uk>
Subject: Perl filtering in INN, and panic: top_env
Message-Id: <8jsd88$33k$1@nntp0.reith.bbc.co.uk>
Keywords: inn innd perl filter panic top_env

I'm trying to compile Perl filter support into innd 2.2.2.  It works to an
extent, but any script I have which uses something non-internal (ie,
strict, vars, etc.) seems to cause the thing to print 'panic: top_env' to
stderr and quit.

I've tried Perl versions 5.004_04, 5.004_05, and 5.005_03.  5.6.0 won't
link, so forget that one.  Solaris 7.  stracing it produces nothing
particularly illuminating (to me at least), perldiag says:

     panic: top_env
         (P) The compiler attempted to do a goto, or something
         weird like that.

which is also unhelpful.  The inn people haven't seen it before, and don't
know anything about it.  The machine is very unloaded, has *plenty* of RAM
(half a gig or so, IIRC), loads of disc, Perl isn't being built with its
own malloc (so the heaps shouldn't conflict, assuming this is an issue;
the docs I can find on embedding it aren't clear on this).

I'm getting rather desperate.  Anyone any ideas?

Thanks.

-- 
Dickon Hood

BBC Internet Services,
Kingswood Warren.


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

Date: 7 Jul 2000 18:27:20 GMT
From: pjh@mccc.edu (Pete Holsberg)
Subject: Perl for Win32 Question
Message-Id: <8k57e8$g6k$1@lawrenceville.mccc.edu>

I'm running Windows NT 4.0.

I have a line in an otherwise successful perl script that looks
like this:

system("c:\utils\date");

Running the script gives:

"The name specified is not recognized as an internal or external
command, operable program or batch file.:

c:\utils\date works from the command line and from a BAT
file.

Is there an explanation? A way to get it to work?

Thanks,
Pete


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

Date: Fri, 7 Jul 2000 12:02:17 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Perl for Win32 Question
Message-Id: <8k59gm$ihc$1@brokaw.wa.com>


Pete Holsberg <pjh@mccc.edu> wrote in message
news:8k57e8$g6k$1@lawrenceville.mccc.edu...
> I'm running Windows NT 4.0.
>
> I have a line in an otherwise successful perl script that looks
> like this:
>
> system("c:\utils\date");

What does that look like to the system?

system ('c:tilsate');

>
> Running the script gives:
>
> "The name specified is not recognized as an internal or external
> command, operable program or batch file.:

I bet it does!  :-)

>
> c:\utils\date works from the command line and from a BAT
> file.
>
> Is there an explanation? A way to get it to work?

The explanation is that you are using double-quoted strings where '\'s are
read as meaning that the next character is a special control character.  You
can avoid this by using single quoted strings: system ('c:\utils\date');  or
using the really cool feature that allows you to use '/'s just like in Unix:
system ("c:/utils/date");

So in summary:

system ('c:\utils\date');

or

system ("c:/utils/date");


But is there a reason you really want to spawn a new process?  Couldn't you
use the various time (and date) functions that Perl provides?

Lauren





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

Date: 7 Jul 2000 19:18:38 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Perl for Win32 Question
Message-Id: <8k5aee$1r1i1$2@ID-24002.news.cis.dfn.de>

hi,
Pete Holsberg <pjh@mccc.edu> wrote:

> I have a line in an otherwise successful perl script that looks
> like this:

> system("c:\utils\date");

> Running the script gives:

> "The name specified is not recognized as an internal or external
> command, operable program or batch file.:

yes, because "\" is a special character in perl (and in most
languages).
the system command would be maybe something like
c:Tilsdate
(i don't know what \u in windows stands for),
and that's not existing.
try 
system("c:\\utils\\date");
instead.

tina


-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."


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

Date: Fri, 07 Jul 2000 15:17:38 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Perl for Win32 Question
Message-Id: <39662CD2.8D908506@attglobal.net>

Lauren Smith wrote:
> 
> So in summary:
> 
> system ('c:\utils\date');
> 
> or
> 
> system ("c:/utils/date");
> 

What about:

my $date = qx'c:\utils\date';

so that he can actually get the output of the command instead of
just the exit status?


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

Date: Mon, 10 Jul 2000 10:38:59 GMT
From: billmez@my-deja.com
Subject: Re: Perl for Win32 Question
Message-Id: <8kc944$ooe$1@nnrp2.deja.com>

In article <8k57e8$g6k$1@lawrenceville.mccc.edu>,
  pjh@mccc.edu (Pete Holsberg) wrote:
> I'm running Windows NT 4.0.
>
> I have a line in an otherwise successful perl
script that looks
> like this:
>
> system("c:\utils\date");
>
> Running the script gives:
>
> "The name specified is not recognized as an
internal or external
> command, operable program or batch file.:
>
> c:\utils\date works from the command line and
from a BAT
> file.
>
> Is there an explanation? A way to get it to
work?
>
> Thanks,
> Pete
>
Pete,

Try escaping the backslash character by using
double "\" as such: system("c:\\utils\\date");

Bill


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 6 Jul 2000 14:25:39 GMT
From: "Jennifer Lill" <jennifer.m.lill_no_spam@lexis-nexis.com>
Subject: perl glob command and "dos" window
Message-Id: <01bfe756$468d1cc0$c1220c8a@lnxlillj1>

I am using perl from PWS on Windows 98. The perl script does a 
glob e.g.
@files=<${pattern}*.dxf>;

When this happens, I get a PERLGLOB window that pops up.

Is there anyway that I can prevent this (the window form popping up)?

I had previously been using opendir/readdir and regular expressions but it
was too slow because the directory was so large (~1000 files) so I changed
to using a glob.

I am running a "older" version of Activeware Perl (5.003?).

Is this "fixed" in later versions?

-- Jennifer


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

Date: 6 Jul 2000 23:17:52 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: perl glob command and "dos" window
Message-Id: <8k3430$9ls$3@slb7.atl.mindspring.net>

Jennifer Lill (jennifer.m.lill_no_spam@lexis-nexis.com) wrote:
: I am using perl from PWS on Windows 98. The perl script does a 
: glob e.g.
: @files=<${pattern}*.dxf>;
: 
: When this happens, I get a PERLGLOB window that pops up.
: 
: Is there anyway that I can prevent this (the window form popping up)?
: 
: I had previously been using opendir/readdir and regular expressions but it
: was too slow because the directory was so large (~1000 files) so I changed
: to using a glob.
: 
: I am running a "older" version of Activeware Perl (5.003?).
: 
: Is this "fixed" in later versions?

Yes, but something else is going on that you aren't telling us about, 
since using Perl's built-ins should be faster than calling an external 
process.  Maybe inefficient regexes or array construction?



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

Date: Fri, 07 Jul 2000 09:20:13 -0400
From: Shawn Corey <shcorey@nortelnetworks.com>
Subject: Re: perl glob command and "dos" window
Message-Id: <3965D90D.875F98EC@nortelnetworks.com>

Jennifer Lill wrote:
> 
> I am using perl from PWS on Windows 98. The perl script does a
> glob e.g.
> @files=<${pattern}*.dxf>;
> 
> When this happens, I get a PERLGLOB window that pops up.
> 
> Is there anyway that I can prevent this (the window form popping up)?
> 
> I had previously been using opendir/readdir and regular expressions but it
> was too slow because the directory was so large (~1000 files) so I changed
> to using a glob.
> 
> I am running a "older" version of Activeware Perl (5.003?).
> 
> Is this "fixed" in later versions?
> 
> -- Jennifer

I was having a similar problem that I fixed by using the function
notation rather than the angle brackets. That is, @files = glob(
"${pattern}*.dxf" );

Shawn


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

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


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