Solved

Newbie Question : Parameters

Posted on 2001-09-07
9
119 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
Comment Utility
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
Comment Utility
Thanks Holli but that doesn't work for me.

Any ideas as to why?

John.
0
 
LVL 6

Expert Comment

by:holli
Comment Utility
please post your script.
0
 
LVL 6

Author Comment

by:Jaymol
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Author Comment

by:Jaymol
Comment Utility
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
Comment Utility
and I did set the file privileges correctly.

John.
0
 
LVL 6

Author Comment

by:Jaymol
Comment Utility
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
Comment Utility
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
Comment Utility
Holli,

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

Thanks again for your help,

John.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now