Re: I'm stuck
Schoeman, Remco wrote: hi i think i see your problem if you edit this line in the comment out section open (mailfile,.$mailfile); to open (mailfile, .$mailfile) or die $0: couldnt open $mailfile :$!; note the space after the in you could also write $mailfile instead of .$mailfile but that's just a matter of taste hope it works in any case it will show the error perl generates MVG Remco Schoeman The Lodge -Original Message- From: Peter Bosmans [mailto:[EMAIL PROTECTED]] Sent: maandag 10 september 2001 17:25 To: [EMAIL PROTECTED] Hi all, Thanks for all your help. I appreciate it very much. I've learned a lot (also about the right syntax) The real problem was the -w at the first line of the program. I removed it and everything seems allright. Again, thanks for the response. Peter Subject: I'm stuck Hi, I've a little problem. The next cgiscript doesn't work. (The mailfile will be created but i get a server error at my browser) But if i comment the 3 lines between comment out, then this script will work. (i see the generated HTML-page at my browser) Does anybody see what the problem is ? Thanks in advance Peter #!/usr/local/bin/perl -w use CGI; $query = new CGI; $teamleader = me.myself\@my_island.see; $mailfile = /home/myself/mymail..$$; # Comment out these lines and this perl script will work open (mailfile,.$mailfile); print mailfile Originator : .$query-param('ORIG').\n; close (mailfile); # End comment out #unlink ($mailfile); print $query-header('text/html'); print $query-start_html('Input CR','me.myself\@my_island.see'); print $query-h1('Your request is sended to the teamleader :'.$teamleader); print $query-end_html(); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: I'm stuck
hi i think i see your problem if you edit this line in the comment out section open (mailfile,.$mailfile); to open (mailfile, .$mailfile) or die $0: couldnt open $mailfile :$!; note the space after the in you could also write $mailfile instead of .$mailfile but that's just a matter of taste hope it works in any case it will show the error perl generates MVG Remco Schoeman The Lodge -Original Message- From: Peter Bosmans [mailto:[EMAIL PROTECTED]] Sent: maandag 10 september 2001 17:25 To: [EMAIL PROTECTED] Subject: I'm stuck Hi, I've a little problem. The next cgiscript doesn't work. (The mailfile will be created but i get a server error at my browser) But if i comment the 3 lines between comment out, then this script will work. (i see the generated HTML-page at my browser) Does anybody see what the problem is ? Thanks in advance Peter #!/usr/local/bin/perl -w use CGI; $query = new CGI; $teamleader = me.myself\@my_island.see; $mailfile = /home/myself/mymail..$$; # Comment out these lines and this perl script will work open (mailfile,.$mailfile); print mailfile Originator : .$query-param('ORIG').\n; close (mailfile); # End comment out #unlink ($mailfile); print $query-header('text/html'); print $query-start_html('Input CR','me.myself\@my_island.see'); print $query-h1('Your request is sended to the teamleader :'.$teamleader); print $query-end_html(); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file write problem
In addition to Randal's lucid explanation of your specific problem. I would encourage you to also use taintmode flag and filter both subject and filename as they are being used to create the file. The commented out attempt to do this with $name shows that you basically may be aware of this, but I figure that I would just raise it quickly since it's important topic. Another minor thing is that I thought was the operator for opening with appending not . But I haven't done appending in a long time so I could be wrong. At 09:51 PM 9/11/2001 +0100, Francesco Scaglioni wrote: Hi, I have a script which collects a comment than should write it to a file. Initialy several scripts did individual jobs but I am combining them. the opening gets the details like this: my $email = param( 'email') || ''; my $text= param( 'text' ) || ''; my $name= param( 'name' ) || ''; # ( my $name )= ( param('name') =~ /^(\w+)$/ ); my $filename= param( 'filename' ) || ''; my $subject = param( 'subject' ) || ''; my $action = param( 'action' ) || ''; my $heading = param( 'heading' ) || ''; my $title = param( 'title') || ''; and then like this: if( $action eq 'start' ) { start(); } elsif ( $action eq 'list') { list( $subject ) ; } elsif ( $action eq 'display' ) { display( $subject , $filename ); } elsif ( $action eq 'get_comment' ) { get_comment( $heading , $subject , $filename ); } elsif ( $action eq 'write_comment'){ write_comment( $name , $email , $text , $subject , $filename ); } else { start() } Then the write bit is: sub write_comment { $name = $_[0]; $email= $_[1]; $text = $_[2]; $subject = $_[3]; $filename = $_[4]; # $COMMENT_DIR = (../data/$subject/.comments); $COMMENT_FILE = (../data/$subject/.comments/$filename) ; if ( ! $name ) { die No value for name; } else { local *WRITE_COMMENT; open ( WRITE_COMMENT, $COMMENT_FILE ) || die $COMMENT_FILE : $!; flock WRITE_COMMENT, LOCK_EX || die cannot lock comment file: $!; print ($text, $name, $email ) || die cannot print hello : $!; close WRITE_COMMENT || die Cannot write to comment file ; $!; } } What is throwing me is that none of it errors or dies but the file remains blank. What am I missing? TIA Francesco -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Gunther Birznieks ([EMAIL PROTECTED]) eXtropia - The Open Web Technology Company http://www.eXtropia.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file write problem
Francesco == Francesco Scaglioni [EMAIL PROTECTED] writes: Francesco flock WRITE_COMMENT, LOCK_EX || die cannot lock comment file: $!; This is not likely doing what you expect. $ perl -MO=Deparse,-p -e 'use Fcntl qw(:flock); flock WRITE_COMMENT, LOCK_EX || die cannot lock comment file: $!;' -e syntax OK sub LOCK_SH {} sub LOCK_EX {} sub LOCK_UN {} sub LOCK_NB {} flock(WRITE_COMMENT, (LOCK_EX() || die(cannot lock comment file: $!))); Note the parentheses. The LOCK_EX is part of the or die, but not the flock. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]