Solved

Newbie Question : Parameters

Posted on 2001-09-07
9
122 Views
Last Modified: 2013-12-25
Hi.

I'm writing a small script that will create text files and store info in them.  Basically, the initial script will just populate a new file with default values, and for this I have a script that works fine.

What I need to do is to be able to pass the script a filename for the data to be stored in.  So, where I have this line of code....

              open(FILE,">filename.txt");

....I need to be able to pass the script the filename and somehow create the file with that name.

Look forward to your comments.

John.
0
Comment
Question by:Jaymol
  • 6
  • 3
9 Comments
 
LVL 6

Accepted Solution

by:
holli earned 50 total points
ID: 6464549
html:
<a href="http://www.myserver.com/myscript.pl?file=myfile.dat>link</a>

OR

<form action="http://www.myserver.com/myscript.pl" method="post">
<input type="hidden" name="file" value="myfile.dat">
</form>

perl:

#!/usr/bin/perl
use CGI;
my $q=new CGI; my $filename=$q->param("file");
open FILE, "> $filename;"
#do your stuff here
close FILE;

print $q->header . $q->start_html . "<b>Info has been saved.</b>" . $q->end_html;
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6464604
Thanks Holli but that doesn't work for me.

Any ideas as to why?

John.
0
 
LVL 6

Expert Comment

by:holli
ID: 6464654
please post your script.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 6

Author Comment

by:Jaymol
ID: 6464666
It's your script.



          #!/usr/bin/perl --

          use CGI;
          my $q=new CGI;
          my $filename=$q->param("file");

          open FILE, "> $filename.txt";
          print FILE "0";
          close FILE;



That's all there is at the minute and it doesn't work.

John.
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6464670
Oh, btw, I know the path is okay as I've already got a simple counter script that's working on the server.

Ta,

John.
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6464695
and I did set the file privileges correctly.

John.
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6464713
Thanks for the help Holli.  I've only graded this C as I had to make quite a few changes to the script to make it work.

Thanks again,

John.
0
 
LVL 6

Expert Comment

by:holli
ID: 6464720
if your remove this "--" then the above (your) code works fine.

call it from the shell: perl script.pl file=myfile
call from browser: http://yourserver.com/script.pl?file=myfile

0
 
LVL 6

Author Comment

by:Jaymol
ID: 6469833
Holli,

Thanks, but the "--" is required or the scripts don't work on my server.

Thanks again for your help,

John.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

777 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