?
Solved

join these two scripts

Posted on 1999-12-01
7
Medium Priority
?
135 Views
Last Modified: 2010-03-05
i have two scripts....
first one puts a file from a computer onto my server
second one lets the user characterise each word in the file they just uploaded......

i include the code below but want to know if this is possible
where it says
"thanks we appreciate the upload of....."
i would like it to automatically start the second script
and open the file that was just uploaded and
continue with the second script

so when someone uploads a file the next thing they see is that file with the drop down menus after each word

both scripts work fine its just that i dont know how to combine them in the way i want


===========sript one================

#!/usr/local/bin/perl
#scipt uploads files to specified dir in the
#format daydaymonthmonthyearyearyearyearuniquenumber.txt

use lib "/usr/local/depot/perl5.005_02/lib/5.00502";

      use CGI;
      use CGI::Carp 'fatalsToBrowser';

      $myCGI = new CGI;
      $outputPath = "/data/local/apache/htdocs/answers";

      print $myCGI->header, $myCGI->start_html;

      if (!$myCGI->param('fileName')) {

         print $myCGI->p("Sorry, your submission didn't include an upload.");

      }
      else {
          $myFileStream = $myCGI->param('fileName');

          ($barefilename) = $myFileStream =~ /.*[:\/\\](.*)/;
          $barefilename = $myFileStream unless $barefilename;

          binmode $myFileStream;

use Fcntl;
      ($d,$m,$y)=(localtime)[3,4,5];
      $m+=1; $y+=1900;
      $date=sprintf("%02d%02d%04d",$d,$m,$y);
      $count=0;
      do{
        $count++;
      }until(  sysopen(OUTFILE,"$outputPath/$date$count.txt",O_WRONLY|O_EXCL|O_C
REAT) || $!
      ne "File exists" );
      defined(fileno(OUTFILE)) || die "Can't create $outputPath/$date$count.txt:
 $!";

          binmode OUTFILE;
          while (<$myFileStream>) {
             print OUTFILE;
          }
          close OUTFILE;
          close $myFileStream;
          print $myCGI->p("Thanks.  We appreciate your upload of $barefilename."
);
      }
  print $myCGI->end_html;

      undef $myCGI;

========================


=============script two=============

#!/usr/local/bin/perl
#this script opens a file and places a drop down #menu after each word in the file
#users can then classify each word in the file
#ie say if each word is good bad or ok
#results are placed into a unique file
#in the format
#this ok
#is good
#a bad
#test ok
use lib "/usr/local/depot/perl5.005_02/lib/5.00502";
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';

$outputPath = "/data/local/apache/htdocs/answers";

print header, start_html('set answers');
                open FILE,'<story.txt' or die "can't open story.txt because $!";

                if( param ){
                        print "<br><br><center>Thanks for setting the test<br><b
r>";
use Fcntl;
                        ($d,$m,$y)=(localtime)[3,4,5];
                        $m+=1; $y+=1900;
                        $date=sprintf("%02d%02d%04d",$d,$m,$y);
                        $count=0;
                        do{
                          $count++;
                        }until(  sysopen(CORRECT,"$outputPath/$date$count.txt",O
_WRONLY|O_EXCL|O_CREAT) || $! ne
                        "File exists" );
                        defined(fileno(CORRECT)) || die "Can't create $outputPat
h/$date$count.txt: $!";

                        while( <FILE> ){
                            while( /(\w+)/g ){
                                print CORRECT "$1 ",(param $1)[$count{$1}++],"\n
";
                            }
                        }
                        close CORRECT;
                }else{
                        print start_form;
                        while( <FILE> ){
                                s/(\w+)/"$1".popup_menu(-name=>"$1",-values=>[(good,bad,ok)])/eg;
                                print;
                       }
                       close FILE;
  print submit, end_form;
                }
      print end_html;
====================
0
Comment
Question by:paulwhelan
  • 5
7 Comments
 

Author Comment

by:paulwhelan
ID: 2246515
can someone repost the joined working script?
0
 
LVL 85

Accepted Solution

by:
ozo earned 1200 total points
ID: 2247814
#!/usr/local/bin/perl
#scipt uploads files to specified dir in the
#format daydaymonthmonthyearyearyearyearuniquenumber.txt

use lib "/usr/local/depot/perl5.005_02/lib/5.00502";

      use CGI;
      use CGI::Carp 'fatalsToBrowser';

      $myCGI = new CGI;
      $outputPath = "/data/local/apache/htdocs/answers";
      $outputPath = ".";

      print $myCGI->header, $myCGI->start_html;

      if (!$myCGI->param('fileName')) {

         print $myCGI->p("Sorry, your submission didn't include an upload.");

      }
      else {
          $myFileStream = $myCGI->param('fileName');

          ($barefilename) = $myFileStream =~ /.*[:\/\\](.*)/;
          $barefilename = $myFileStream unless $barefilename;

          binmode $myFileStream;

use Fcntl;
      ($d,$m,$y)=(localtime)[3,4,5];
      $m+=1; $y+=1900;
      $date=sprintf("%02d%02d%04d",$d,$m,$y);
      $count=0;
      do{
        $count++;
      }until(  sysopen(OUTFILE,"$outputPath/$date$count.txt",O_WRONLY|O_EXCL|O_CREAT) || $!
      ne "File exists" );
      defined(fileno(OUTFILE)) || die "Can't create $outputPath/$date$count.txt:
 $!";

          binmode OUTFILE;
          while (<$myFileStream>) {
             print OUTFILE;
          }
          close OUTFILE;
          close $myFileStream;
          print $myCGI->p("Thanks.  We appreciate your upload of $barefilename."
);
          &two;
      }
  print $myCGI->end_html;

      undef $myCGI;

sub two{
#!/usr/local/bin/perl
#this script opens a file and places a drop down #menu after each word in the file
#users can then classify each word in the file
#ie say if each word is good bad or ok
#results are placed into a unique file
#in the format
#this ok
#is good
#a bad
#test ok
#use lib "/usr/local/depot/perl5.005_02/lib/5.00502";
#use CGI qw/:standard/;
#use CGI::Carp 'fatalsToBrowser';

#$outputPath = "/data/local/apache/htdocs/answers";

#print header, start_html('set answers');
                open FILE,'<story.txt' or die "can't open story.txt because $!";

                if( $myCGI->param ){
                        print "<br><br><center>Thanks for setting the test<br><br>";
use Fcntl;
                        ($d,$m,$y)=(localtime)[3,4,5];
                        $m+=1; $y+=1900;
                        $date=sprintf("%02d%02d%04d",$d,$m,$y);
                        $count=0;
                        do{
                          $count++;
                        }until(  sysopen(CORRECT,"$outputPath/$date$count.txt",O_WRONLY|O_EXCL|O_CREAT) || $! ne
                        "File exists" );
                        defined(fileno(CORRECT)) || die "Can't create $outputPath/$date$count.txt: $!";

                        while( <FILE> ){
                            while( /(\w+)/g ){
                                print CORRECT "$1 ",($myCGI->param($1))[$count{$1}++],"\n";
                            }
                        }
                        close CORRECT;
                }else{
                        print $myCGI->start_form;
                        while( <FILE> ){
                                s/(\w+)/"$1".$myCGI->popup_menu(-name=>"$1",-values=>[(good,bad,ok)])/eg;
                                print;
                       }
                       close FILE;
  print $myCGI->submit, $myCGI->end_form;
                }
#      print end_html;
}
0
 

Author Comment

by:paulwhelan
ID: 2249074
i think i got too confused there.....

heres what id like it to do

first people can upload a file and this
isnt placed onto the server. what happens is a
dropdown menu is placed after every word
in that file

then the file that is placed onto the server has a unique id and contains the words and the classifications.....

so if i upload test.txt which contains the text
"this is a test" i click to send the file
and the next screen i get has
this [click here] is [click here] a [click here] test [click here]
then when i classify the words and unique file is opened (ie 021219991.txt for the first file opened on the 2nd of dec 1999) and that file contains
something like this
this ok
is ok
a bad
test good

thats all i want it to do
heres the html i use to call the cgi

  <form action="http://myserver/cgi-bin/uploadandtest.cgi" method="po
st" enctype="multipart/form-data">
      <input type="file" name="fileName"><BR>
      <input type="submit" value="Send File">
      </form>

can someone post what uploadandtest.cgi should look like?
thanks for you help ozo
ozo when i tried to run what u posted it
said that it couldnt create the unique id file
(and i did chmod 777 on the relevant dir)
thanks
paul

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:paulwhelan
ID: 2249253
ozo
i got the permissions right now
but when i click send file
it says "thanks for setting the test"
but i never even got a chance to set the test
paul
0
 

Expert Comment

by:spiegei
ID: 2252786
I would do this with a libarary .pm file. Set up the second script to be a fucnction and put it in a file with a .pm extension.
(example: dropdown.pm) and place similar code as below around it.
Step 1:

package dropdown;
require Exporter;
@ISA =qw{Exporter};
@EXPORT=qw{dropdown};


sub dropdown {

 
 your code from second script here
}


Step 2:

In your first script at the top make a reference to this pm file with the correct path to it.
example use dropdown.pm     or use ../library/dropdown.pm


Step3:
Call the second script in the .pm from the first script by just calling the function
dropdown();
0
 

Author Comment

by:paulwhelan
ID: 2252907
i think it would be best if someone could post working code that does this

heres what i want it to do again

users upload a file when they hit "send file" the next thing
they see is the file they just uploaded with a dropdown menu (options are "good" "bad" and "ok") after every word in that file
 
then at the end of the page with all the words and dropdown menus there is a submit button....
when they click this button a unique file is opened
and the results of setting the test are in there


so if i upload test.txt which contains the text
"this is a test" i click to send the file
and the next screen i get has
this [click here] is [click here] a [click here] test [click here]
then when i classify the words and hit submit a unique file is opened (ie 021219991.txt for the first file opened on the
2nd of dec 1999) and that file contains
something like this
                this ok
                is ok
                a bad
                test good

                thats all i want it to do
                heres the html i use to call the cgi

                  <form action="http://myserver/cgi-bin/uploadandtest.cgi" method="po
                st" enctype="multipart/form-data">
                      <input type="file" name="fileName"><BR>
                      <input type="submit" value="Send File">
                      </form>

                can someone post what uploadandtest.cgi should look like?

thanks for you help

                paul
0
 

Author Comment

by:paulwhelan
ID: 2259230
spiegei u shouldnt answer questions
just put your answer as a comment my points are
lost now and i worked out the answer myself
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question