Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

Newbie Question : Parameters

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
Jaymol
Asked:
Jaymol
  • 6
  • 3
1 Solution
 
holliCommented:
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
 
JaymolAuthor Commented:
Thanks Holli but that doesn't work for me.

Any ideas as to why?

John.
0
 
holliCommented:
please post your script.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
JaymolAuthor Commented:
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
 
JaymolAuthor Commented:
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
 
JaymolAuthor Commented:
and I did set the file privileges correctly.

John.
0
 
JaymolAuthor Commented:
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
 
holliCommented:
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
 
JaymolAuthor Commented:
Holli,

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

Thanks again for your help,

John.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now