Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Newbie Question : Parameters

Posted on 2001-09-07
9
Medium Priority
?
128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 6

Accepted Solution

by:
holli earned 100 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
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.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

596 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