I have completed a script that works on my PC when all files are in the same directory. However, when I upload..stops working. I think it's something to do with the pathnames...
Basic premise:

1) script reads existing db created by formmail clone into array

(formmail script writes correctly to path of /home/hampton1/data/student.dat)

2) parse each line to create two more arrays

3) write out a second file with the values in the arrays.

4) Last read the newly created second file and write a third file with js in it.

The new files created in this script are not being created so js in html page is throwing up.

Newbie to perl but longtime DB programmer... big learning curve!
#!/usr/bin/perl use CGI use File::Copy; use strict; use warnings; # define names of student reg info file,student count file and name of + js file to be sritten out $sdata="/home/hampton1/data/student.dat"; $scnt="/home/hampton1/data/student_count.dat"; $jscd="/home/hampton1/data/jscd.js"; # open existing student reg file open(SDATA,"$sdata")|| die("Could not open file!"); # Put file into array @line = <SDATA>; # delete existing count & js file - so they can be to be recreated if (-e "/home/hampton1/data/student_count.dat") { unlink($scnt); } if (-e "/home/hampton1/data/jscd.js") { unlink($jscd); } # create file(> symbol is overwriting) open (SCNT,">$scnt"); # set all permissions chmod 0777, $scnt or die "Couldn't chmod $scnt: $!"; # create file(> symbol is overwriting) open (JSCD,">$jscd"); # set all permissions chmod 0777, $jscd or die "Couldn't chmod $jscd: $!"; # Parse fields in first line ($empty, $dtereg, $timereg, $c1,$c1tot, $c2, $c2tot) = split(/\|/,$lin +e[0]); # Load c1tot array from first record @clsid=$c1; @cqty = $c1tot; if ($c2 ne " ") { push (@clsid,$c2); push (@cqty,$c2tot); } @line = pop(@line); close SDATA; foreach $listitem (@line) { # remove CR/LF chop $listitem; # parse fields in each subsequent line ($empty, $dtereg, $timereg, $c1,$c1tot, $c2, $c2tot) = split(/ +\|/,$listitem); # see if class exists in array already if (grep {$_ eq $c1} @clsid) { $idx = indexArray($c1,@clsid); $cqty[$idx]+= +$c1tot; } # else add to array else { push (@clsid,$c1); push (@cqty,$c1tot); $idx = indexArray($c1,@clsid); } # See if class (2) exists in array already if (grep {$_ eq $c2} @clsid) { $idx = indexArray($c2,@clsid); $cqty[$idx]+= +$c2tot; } # else add class 2 to array else { push (@clsid,$c2); push (@cqty,$c2tot); $idx = indexArray($c2,@clsid); } } $inum = 0; # find last element # (# elements in array0 $idxcid = $clsid; # print result to student count file while ($inum <= $idxcid) { print SCNT "$clsid[$inum]\|"; print SCNT "$cqty[$inum]\n"; $inum = ++$inum; } close SCNT; sub indexArray{for(1..@_){$_[0]eq$_[$_]&&return$_-1}-1} # print results to javascript file print JSCD "function getarray ()\n"; print JSCD "{\n"; print JSCD "jclsid = []\n"; $inum = 0; # find last element # (# elements in array) $idxcid = $clsid; while ($inum <= $idxcid) { print JSCD "jclsid[$inum] = \"$clsid[$inum]\"\n"; $inum = ++$inum; } print JSCD "jclscnt = []\n"; $inum = 0; # find last element # (# elements in array) $idxcid = $clsid; while ($inum <= $idxcid) { print JSCD "jclscnt[$inum] = $cqty[$inum]\n"; $inum = ++$inum; } print JSCD "}\n"; close JSCD; # copy js file to public_html dir where all other js file are # is this needed??? $newjscd ='/home/hampton1/public_html/jscd.js"; copy($jscd, $newjscd) or die "File cannot be copied.";
script is in /public_html/cgi-bin of course but have I specified the right path to the other files? Any assistance would be greatly appreciated! JV

In reply to specifying path to files by jvallee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.