"Can't open file" ( flat file ) and "flock()unimplemented ..."

"Can't open file" ( flat file ) and "flock()unimplemented ..."

Post by Justi » Tue, 15 Aug 2000 04:00:00



This is a wierd one that I've run into - me being Perl the newbie that I am.
        Here is a simple script that I have been trying to make work.
Everything works fine until I get to the part where it tries to open the
file. On Unix, I get the following error message:

Software error:

flock() unimplemented on this platform at c:/apache/cgi-bin/catalog.cgi line
35.

On Windows 98 running Apache it just says that it couldn't open the file. I
can't find anything wrong with my code - if  anyone here could take a quick
look and give me a few pointers I'd appreciate it. Thanks,

Justin

---- Here is the code:

#!/usr/local/bin/perl

use CGI;
use CGI::Carp qw( fatalsToBrowser );

$query = new CGI;

$catalog_file = "products.txt";
$cart_file = "cart.txt";

if ($query->param('product_id')) {
 if ($query->cookie('session_id')) {
  $session_id = ($query->cookie('session_id'));
 }
 else {
  $session_id = time . $$;
 }
 &set_variables;
 &add_to_cart;
 &print_page_start;
 &open_catalog;
 &display_catalog;
 &print_page_end;

Quote:}

else {
 &print_page_start;
 &open_catalog;
 &display_catalog;
 &print_page_end;

Quote:}

sub add_to_cart {
 open (CART, "+>> $cart_file")
  or die "Can't open shoppint cart file";
 flock CART, 2;
 seek CART, 0, 0;


 $found = 'no';

  chomp $record;
  ($rec_session_id, $rec_product_id, $rec_quantity) =
   split /\t/, $record;
  if (($session_id eq $rec_session_id) and
  ($product_id eq $rec_product_id))

  $new_quantity = $quantity + $rec_quantity;
  $new_record = "$session_id\t$product_id\t$new_quantity";
  $record = $new_record;
  $found = 'yes';
 }
  $record .= "\n";

 }
 seek CART, 0, 0;
 truncate CART, 0;

 if ($found eq 'no') {
  print CART "$session_id\t$product_id\t$quantity\n";
 }
 close CART;

Quote:}

sub set_variables {
 $product_id = $query->param('product_id');
 $quantity = $query->param('quantity');

Quote:}

sub open_catalog {
 eval {
  open (CATALOG, "< $catalog_file")
   or die "Can't open $catalog_file";
 };

Quote:}

sub display_catalog {
 print "<CENTER>\n<TABLE BORDER=1 CELLPADDING=4\n";
 print "<TR>\n<TH>Description</TH>\n<TH>Price</TH>\n</TR>\n";

 while (<CATALOG>) {
  ($product_id, $product_desc, $product_price) = split /\t/;
  print "<TR>\n";
  print "<FORM>\n";
  print "<INPUT TYPE=\"hidden\" NAME=\"product_id\" ";
  print "VALUE=\"$product_id\">\n";
  print "<TD>$product_desc</TD>\n<TD>$product_price</TD>\n";
  print "<TD><INPUT TYPE=\"text\" NAME=\"quantity\" ";
  print "VALUE=\"1\" SIZE=2></TD>\n";
  print "<TD><INPUT TYPE=\"submit\" VALUE=\"add\"></TD>\n";
  print "</FORM>\n";
  print "</TR>\n";
 }
 print "</TABLE>\n</CENTER>\n";

Quote:}

sub print_page_start {
 if ($session_id) {
  $cookie = $query->cookie(-name=>'session_id',
     -value=>$session_id);
  print $query->header(-cookie=>$cookie);
 }
 else {
  print $query->header;
 }
 print "<HTML>\n<HEAD>\n<TITLE>PC Product Catalog</TITLE>\n";
 print "</HEAD\n<BODY>\n";
 print "<H1 ALIGN=\"center\">PC Product Catalog</H1>\n";

Quote:}

sub print_page_end {
 print "<P><CENTER><B>";
 print "<A HREF=\"cart.pl\">view cart</A></B></CENTER></P>\n";
 print "</BODY>\n</HTML>\n";

Quote:}

--- Thanks again
 
 
 

"Can't open file" ( flat file ) and "flock()unimplemented ..."

Post by Bill Mosele » Tue, 15 Aug 2000 04:00:00



remarked...

Quote:> This is a wierd one that I've run into - me being Perl the newbie that I am.
> On Unix, I get the following error message:

> flock() unimplemented on this platform at c:/apache/cgi-bin/catalog.cgi line
> 35.

c:/apache/... is a unix path?

--
Bill Moseley

 
 
 

"Can't open file" ( flat file ) and "flock()unimplemented ..."

Post by Justi » Tue, 15 Aug 2000 04:00:00


Ack, sorry - I got it backwards; the flock() unimplemented is on Win98 and
"couldn't open file" is on Unix.



> remarked...
> > This is a wierd one that I've run into - me being Perl the newbie that I
am.

> > On Unix, I get the following error message:

> > flock() unimplemented on this platform at c:/apache/cgi-bin/catalog.cgi
line
> > 35.

> c:/apache/... is a unix path?

> --
> Bill Moseley

 
 
 

"Can't open file" ( flat file ) and "flock()unimplemented ..."

Post by David Efflan » Wed, 16 Aug 2000 12:38:29



>Ack, sorry - I got it backwards; the flock() unimplemented is on Win98 and
>"couldn't open file" is on Unix.

There is no flock on Win98 and your die error would tell you more if it
included the reason for the open error in the $! variable.

perldoc -f open doesn't mention anything about +>>, which may be
your error.  You should be using +< (read/write access) instead.  You
immediately seek the beginning of the file anyway to read existing data.
Also I don't think you can open a file for read/write if it does not
exist, so you should use > instead when creating a new file.




>> remarked...
>> > This is a wierd one that I've run into - me being Perl the newbie that I
>am.

>> > On Unix, I get the following error message:

>> > flock() unimplemented on this platform at c:/apache/cgi-bin/catalog.cgi
>line
>> > 35.

>> c:/apache/... is a unix path?

>> --
>> Bill Moseley

--

http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/  http://cgi-help.virtualave.net/
 
 
 

1. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

My machine: P166+mmx, 32mb ram, 4gb HD with Win95 and Win NT 4.0 and
redhat5.1 co-existed in different partitions.

I issued "sndconfig" within a xterm inside X Window, The program
detects the SB 16 pnp card sets it up with no error message, but when
it launch ModProbe to test out, it gets a message states: An error was
encountered running the ModProbe program."  I tried different IRQ
settings, all ends with the same message.

2nd, When I try to mount /dev/cdrom from File Systerm Manager, the
following error is returned:  Can't find /dev/hdb in /etc/mtab or
/etc/fstab.

3nd, When my machine boots, it halts at "Sendmail" for about 3-5 mins
before it goes to next step.  Obviously there isn't any mail system on
the machine right now because it is a standalone.  How can take this
mail thing out and speed up booting?

last one, Is my Zoom 56k PCI FaxModem a Windmodem that Linux can't use
to connect me to my local isp?

Experts help me out please. thanks.

2. Using Apache 1.3.14 Binary Distribution on Solaris 2.7/2.8

3. GETSERVBYNAME()????????????????????"""""""""""""

4. regarding drawing on screen without windows.

5. Application Input as a "Pipe" not a "flat-File" ???

6. how to link up a linux server and a mac ppc?

7. "Standard Journaled File System" vs "Large File Enabled Journaled File System"

8. C2, BSM and aset ?????

9. Type "(", ")" and "{", "}" in X...

10. "cd file.zip" instead of "unzip file.zip"?

11. "> file" versus "cp /dev/null file"

12. rss" and "stack" and "data" in /etc/security/limits file

13. Is "sh file" equivalent to "cat file | sh"