kjg has asked for the wisdom of the Perl Monks concerning the following question:

Hi script is below. The emailing part of the thing works fine, but the file isn't being output. Any clues?

use Win32::ODBC; # Obtain Environment Variables including passed parameters if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } else { &error('request_method'); } $remhost = $ENV{'REMOTE_HOST'}; $remaddr = $ENV{'REMOTE_ADDR'}; $remuser = $ENV{'REMOTE_USER'}; %Config = ('Suffix',''); foreach $pairs (@pairs) { # Split the pair up into individual variables. + # local($name, $value) = split(/=/, $pairs); # Decode the form encoding on the name and value variables. + # # v1.92: remove null bytes + # $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/\0//d; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/\0//d; # If the field name has been specified in the %Config array, it wi +ll # # return a 1 for defined($Config{$name}}) and we should associate + # # this value with the appropriate configuration variable. If this + # # is not a configuration form field, put it into the associative + # # array %Form, appending the value with a ', ' if there is already + a # # value present. We also save the order of the form fields in the + # # @Field_Order array so we can use this order for the generic sort +. # if (defined($Config{$name})) { $Config{$name} = $value; } else { if ($Form{$name} ne '') { $Form{$name} = "$Form{$name}, $value"; } else { push(@Field_Order,$name); $Form{$name} = $value; } } } # The next line removes any extra spaces or new lines from the + # # configuration variables, which may have been caused if your editor + # # wraps lines after a certain length or if you used spaces between fie +ld # # names or environment variables. #$Config{'Suffix'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g; #$Config{'Suffix'} =~ s/(\s+)?\n+(\s+)?//g; $Form{'Actions'} =~ s/(\s+|\n)?,(\s+|\n)?/ /g; $Form{'Actions'} =~ s/(\s+)?\n+(\s+)?//g; $Form{'Feedback'} =~ s/(\s+|\n)?,(\s+|\n)?/ /g; $Form{'Feedback'} =~ s/(\s+)?\n+(\s+)?//g; $datetime = localtime(time); # file path \Inetpub\wwwdev\regfinser\_private\ # my $filepath = "\\Inetpub\\wwwybs\\ybsone\\_private\\fosfeedback_tes +t.csv"; # my $filepath = "\\Inetpub\\wwwdev\\regfinser\\_private\\fosfeedback_ +test.csv"; my $filepath = "\\Inetpub\\wwwdev\\regfinser\\_private\\ybs1028a_tes +t.csv"; print "Content-Type:text/html\n"; print "\n"; print "<HTML>\n"; # Debug routine to check all variables are being passed while (my ($name, $id)= each %Form) { print "$name : has value : $Form($name) <BR>\n"; } print "<HEAD>\n"; print "<TITLE>Entering User Details..gjhgh..</TITLE>\n"; print "</HEAD>\n"; print "<BODY bgcolor=\"ffffff\">\n"; print "<font face=\"Arial\">\n"; # try to get rid of blank lines problem. chomp($Form{'Help'}); if ($Form{'Help'} eq '') { print "<H1>ERROR form data not received</H1>Press the back button an +d submit again, no data has been saved<BR><BR>"; print "This could of been because you double clicked the submit butt +on, you only need to click it once"; print "<BR><BR>"; } else { # #while (my ($name,$id) = each %Form) { # print "<BR>$name : $Form{$name}"; #} print "<HEAD>\n"; print "<TITLE>Entering User Details..gjhgh..</TITLE>\n"; print "</HEAD>\n"; print "<BODY bgcolor=\"ffffff\">\n"; print "<font face=\"Arial\">\n"; $nowseconds=time; # Output results to file my $fileexist = 0; if (open FORMOUTPUT, join("","<",$filepath)) { $fileexist=1; } print "$fileexist\n"; print "$filepath\n\n"; (open FORMOUTPUT, join("",">>",$filepath)) or (open TESTOPENED, join(" +",">",$filepath)); if ($fileexist==0) { # print all headings out print "Outputting Headings\n\n"; print FORMOUTPUT "date,Manager,Briefer,No_Briefings_Deadline1,People +_Briefed_Deadline1,No_Briefings_Deadline2,People_Briefed_Deadline2,No +_Briefings_Late,People_Briefed_Late,Number_Of_Actions,Actions,Feedbac +k,CB_Length,CB_Detail,CB_Relevant,CB_Understand,CB_Rating,Core_Brief_ +Comments,LB_Length,LB_Detail,LB_Relevant,LB_Understand,LB_Rating,Loca +l_Brief_Comments,Help\n"; } #print "Writing Data\n\n"; print FORMOUTPUT "\"$Form{'date'}\","; #print "date: $Form{'date'}\n"; print FORMOUTPUT "\"$Form{'Manager'}\","; #print "manager: $Form{'Manager'}\n"; print FORMOUTPUT "\"$Form{'Briefer'}\","; print FORMOUTPUT "\"$Form{'No_Briefings_Deadline1'}\","; print FORMOUTPUT "\"$Form{'People_Briefed_Deadline1'}\","; print FORMOUTPUT "\"$Form{'No_Briefings_Deadline2'}\","; print FORMOUTPUT "\"$Form{'People_Briefed_Deadline2'}\","; print FORMOUTPUT "\"$Form{'No_Briefings_Late'}\","; print FORMOUTPUT "\"$Form{'People_Briefed_Late'}\","; print FORMOUTPUT "\"$Form{'Number_Of_Actions'}\","; print FORMOUTPUT "\"$Form{'Actions'}\","; print FORMOUTPUT "\"$Form{'Feedback'}\","; print FORMOUTPUT "\"$Form{'CB_Length'}\","; print FORMOUTPUT "\"$Form{'CB_Detail'}\","; print FORMOUTPUT "\"$Form{'CB_Relevant'}\","; print FORMOUTPUT "\"$Form{'CB_Understand'}\","; print FORMOUTPUT "\"$Form{'CB_Rating'}\","; print FORMOUTPUT "\"$Form{'Core_Brief_Comments'}\","; print FORMOUTPUT "\"$Form{'LB_Length'}\","; print FORMOUTPUT "\"$Form{'LB_Detail'}\","; print FORMOUTPUT "\"$Form{'LB_Relevant'}\","; print FORMOUTPUT "\"$Form{'LB_Understand'}\","; print FORMOUTPUT "\"$Form{'LB_Rating'}\","; print FORMOUTPUT "\"$Form{'Local_Brief_Comments'}\","; print FORMOUTPUT "\"$Form{'Help'}\","; printf FORMOUTPUT "\"%s\"",CurrentTime(); print FORMOUTPUT "\n"; close FORMOUTPUT; } # End else at begining if no data received print "</body></html>"; # # Send the Email to the Branch Co-ordinator # { open MAIL, "|c:/windmail/windmail -t"; print MAIL "To: kjglynn\@ybs.co.uk\n"; print MAIL "From: Focus on Success Database\n"; print MAIL "Subject: Focus on Sucess Feedback\n\n"; print MAIL "The following values have been posted :\n"; print MAIL "\n"; print MAIL "Date: $Form{'date'}\n"; print MAIL "Who briefed this briefer: $Form{'Manager'}\n"; print MAIL "I am: $Form{'Briefer'}\n"; print MAIL "Number of briefings before the 5 day deadline: $Form{'No_B +riefings_Deadline1'} \n"; print MAIL "Number of people briefed before the 5 day deadline: $Form{ +'People_Briefed_Deadline1'}\n"; print MAIL "Number of briefings before the Feedback deadline: $Form{'N +o_Briefings_Deadline2'} \n"; print MAIL "Number of people briefed before the Feedback deadline: $Fo +rm{'People_Briefed_Deadline2'}\n"; print MAIL "Number of briefings after the Feedback deadline: $Form{'No +_Briefings_Late'} \n"; print MAIL "Number of people briefed after the Feedback deadline: $For +m{'People_Briefed_Late'}\n"; #print MAIL "\n"; #print MAIL "\n"; print MAIL "How many actions the team are taking: $Form{'Number_Of_Act +ions'}\n"; print MAIL "Details of actions being taken: $Form{'Actions'}\n"; print MAIL "Feedback for Senior Management: $Form{'Feedback'}\n"; #print MAIL "\n"; #print MAIL "\n"; print MAIL "How long was the Corporate Brief: $Form{'CB_Length'}\n"; print MAIL "How detailed was the Corporate Brief: $Form{'CB_Detail'}\n +"; print MAIL "How relevant the Corporate Brief: $Form{'CB_Relevant'}\n"; print MAIL "How easy was it to understand the Corporate Brief: $Form{' +CB_Understand'}\n"; print MAIL "Your overall rating of the Corporate Brief: $Form{'CB_Rati +ng'}\n"; print MAIL "Any other comments on the Corporate Brief: $Form{'Core_Bri +ef_Comments'}\n"; #print MAIL "\n"; #print MAIL "\n"; print MAIL "How long was the Local Brief: $Form{'LB_Length'}\n"; print MAIL "How detailed was the Local Brief: $Form{'LB_Detail'}\n"; print MAIL "How relevant the Local Brief: $Form{'LB_Relevant'}\n"; print MAIL "How easy was it to understand the Local Brief: $Form{'LB_U +nderstand'}\n"; print MAIL "Your overall rating of the Local Brief: $Form{'LB_Rating'} +\n"; print MAIL "Any other comments on the Local Brief: $Form{'Local_Brief_ +Comments'}\n"; #print MAIL "\n"; #print MAIL "\n"; print MAIL "More help wanted with preparing Local Brief: $Form{'Help'} +\n"; printf MAIL "Time: %s\"",CurrentTime();"\n"; print MAIL "\n.\n"; close MAIL; } exit; sub CurrentDate { my $input = $_[0]; my %Months = ('Jan','January','Feb','Febuary','Mar','March','Apr','A +pril','May','May','Jun','June','Jul','July','Aug','August','Sep','Sep +tember','Oct','October','Nov','November','Dec','December'); localtime(time)=~m/(\w+)\s(\w+)\s+(\w+)\s+(\w+)\S(\w+)\S(\w+)\s+(\w+ +)/; $now = "$2 $3 $7 $4:$5:$6"; $input = $now; chomp($input); if ($input=~/(\w+) (\d+) (\d+) (\d+):(\d+):\d+/) { return "$2 $1 $3"; } else { return "error"; } } sub CurrentTime { my $input = $_[0]; my %Months = ('Jan','January','Feb','Febuary','Mar','March','Apr','A +pril','May','May','Jun','June','Jul','July','Aug','August','Sep','Sep +tember','Oct','October','Nov','November','Dec','December'); localtime(time)=~m/(\w+)\s(\w+)\s+(\w+)\s+(\w+)\S(\w+)\S(\w+)\s+(\w+ +)/; $now = "$2 $3 $7 $4:$5:$6"; $input = $now; chomp($input); if ($input=~/(\w+) (\d+) (\d+) (\d+):(\d+):\d+/) { return "$4:$5"; } else { return "error"; } }

Oh and to clarify, the permissions on the folder as file as I have adpated this script from another that writes to the same file and which works just fine. Any help would be gratefully recieved!

Janitored by Arunbear - added readmore tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: Why isn't the file being produced?
by dragonchild (Archbishop) on Apr 19, 2005 at 15:24 UTC
    Start taking stuff out of the script until you have the smallest piece of code that reproduces the problem. At that point, your problem will become very evident.

    Also, if you want our help in debugging something, adding "use strict" and "use warnings" to the top of your script will go a long ways. That's the first thing we generally suggest, just because Perl is much better at debugging stupid errors than we are.

Re: Why isn't the file being produced?
by Fletch (Bishop) on Apr 19, 2005 at 15:34 UTC

    Not to mention you should use CGI rather than your own argument parsing, and POSIX::strftime rather than your own date formatting.

Re: Why isn't the file being produced?
by gellyfish (Monsignor) on Apr 19, 2005 at 15:26 UTC

    As well as dragonchild's fine advice you should be checking the success of the opens that you are doing and printing the error message in $! if they fail.

    /J\

Re: Why isn't the file being produced?
by blazar (Canon) on Apr 19, 2005 at 15:56 UTC
    Hi script is below. The emailing part of the thing works fine, but the file isn't being output. Any clues?
    As a side note to the advices you already received I would lkie to point out that although posting full code samples is more tolerated here than elsewhere (e.g. in clpmisc), it may be sensible to prepare properly trimmed down minimal examples still exhibiting the problem you're asking for help about.

    A nice side effect is that chances are you find the solution yourself while doing so.

Re: Why isn't the file being produced?
by BigRare (Pilgrim) on Apr 19, 2005 at 16:35 UTC
    Are you sure you want to use:
    my $filepath = "\\Inetpub\\wwwdev\\regfinser\\_private\\ybs1028a_test.csv";
    And Not:
    my $filepath = "c:/Inetpub/wwwdev/regfinser/_private/ybs1028a_test\.csv";

    For Path information: Paths in Perl
Re: Why isn't the file being produced?
by kjg (Sexton) on Apr 19, 2005 at 15:16 UTC
    And just to add, the script works as the form variables are displayed jsut fine when using the debug!