Adding to a perl script automatically

M

MMWJones

Hi,

I have a perl cgi script which defines popup_menu and values in the
drop down list. More values may be added to this over time. People
that don't know much about the script might not want to enter the
script and type in values 'manually'.

Is there a way of writing a script that will ask the user for a value
and be able to access the script and put the value in the correct
place automatically?

If so how would i go about doing this? In a .pl script or .sh script?

Thanks,

Matt
 
J

Josef Moellers

Hi,

I have a perl cgi script which defines popup_menu and values in the
drop down list. More values may be added to this over time. People
that don't know much about the script might not want to enter the
script and type in values 'manually'.

Is there a way of writing a script that will ask the user for a value
and be able to access the script and put the value in the correct
place automatically?

If so how would i go about doing this? In a .pl script or .sh script?

As far as this operation is concerned, your Perl CGI script is just a
plain text file where you want to add some text. Depending upon the
structure of the script, this may be a very difficult task or it may be
an easy task.
First of all, you may want to modify your Perl CGI script such that
adding the relevant entries is easy, e.g. put the entries into an array
and add a marker:
my @menu = (
'Entry 1',
'Entry 2',
:
'Entry n',
# Add new entries for menu here
);
Use this array when constructing your CGI menu.

Then, use whatever language you're familiar with to insert new entries
before the line containint "# Add new entries for menu here"

Just give it a try and if your program doesn't work, show us the code
and we can most likely help.
 
M

MMWJones

excellent thanks....that will help me get my head around it for now.
I'll see what i can come up with.
 
X

xhoster

Hi,

I have a perl cgi script which defines popup_menu and values in the
drop down list. More values may be added to this over time. People
that don't know much about the script might not want to enter the
script and type in values 'manually'.

I think that this is a spectacularly bad idea. If you want people who
don't know much about Perl to configure aspects of your Perl program, you
should make a non-Perl configuration file (or database) for them to use for
that purpose.
Is there a way of writing a script that will ask the user for a value
and be able to access the script and put the value in the correct
place automatically?

Sure. If you save this to a script named add.pl, when run it will add the
typed in string to itself. You could easily make it work on scripts other
than itself just be changing the string assigned to @ARGV in the "local".

#!/usr/local/bin/perl
use strict;
use warnings;
my @x=(
#MyUniqueMarker,
"a",
"b",
"c",
);
print "Current values is @x\n";
print "What should I add?\n";
my $new = <>;
close STDIN or die $!;
chomp $new;
local ($^I,$/,@ARGV)=('.bak',undef,"add.pl");
$_=<>;
s/#MyUniqueMarker,\n/#MyUniqueMarker,\n"$new",\n/ or warn;
print;

But the fact that it can be done doesn't make a good idea. Somewhat better
than this, but still not as good as having a separate config file, is to
use the __END__ or __DATA__ tokens to separate the program from the data
within one file.
If so how would i go about doing this? In a .pl script or .sh script?

I certainly wouldn't try in .sh, but then again I don't read or post to
sh scripting newsgroups, so clearly I am biased in that regard.

Xho
 
S

Skye Shaw!@#$

I think that this is a spectacularly bad idea. If you want people who
don't know much about Perl to configure aspects of your Perl program, you
should make a non-Perl configuration file (or database) for them to use for
that purpose.


Indeed.

Are these people programmers? If not, they could render the script
unusable.

'Odd number of elements in hash assignment' and 'Bare word XYZ'
warnings to mind; assuming you are useING warnings.

Configuration interfaces are good.

On the other hand, if the values required remain minimal, and your
site doesn't receive a lot of traffic, you could retrieve the values
from a CSV file. If changes need to be made, they can be done in Open
Office or Excel, something that will output properly formated data.
 
M

Michele Dondi

Is there a way of writing a script that will ask the user for a value
and be able to access the script and put the value in the correct
place automatically?

Certainly: it's enough to have a script with the capability of
modifying itself. Only, you should do that *very* carefully. Otherwise
I foresee security nightmares waiting in the shadow to haunt you. But
seriously, why don't you hold the values elsewhere, e.g. in a plain
text file if nothing else, and duly update that if needed?

BTW: absolutely *not* required, but from the UI POV this seems a
perfect task for some AJAX thingie...
If so how would i go about doing this? In a .pl script or .sh script?

..pl and .sh are nothing but extensions. A perl script certainly *can*
modify the file it's written in. If you want to delegate that business
to an external shell script, then you certainly *can* as well.


Michele
 
M

Michele Dondi

I think that this is a spectacularly bad idea. If you want people who
don't know much about Perl to configure aspects of your Perl program, you
should make a non-Perl configuration file (or database) for them to use for
that purpose.

Well, a priori not necessarily: I have a *tiny* script of mine which I
had originally posted at http://perlmonks.org/?node_id=417646 (now
that I look at it... damn, that early habit of mine of using -l too
much!) and with which I tried hard to make it idiot proof for
"maintainers" to add/modify entries at the bottom. It seems to have
worked fine at a location for quite about some time.


Michele
 
M

MMWJones

I thought i would continue in this post rather than start a new one as
it follows on from this problem.

I have managed to use an intermediate text file to store a list which
can be added to with one cgi script and accessed with another script.
That seemed easy compared to my current problem. Im basically trying
to do the same thing but with setting up a radio set. So the script
will also add a radio group to another cgi script. I thought i would
use the same principle as before and list the radio sets in a text
file so to speak.

I can create the radio sets in html but it does not complete the
required action. Therefore i would like to know if i can use the
actual cgi in the text file and then read this into the other script.

Example:

$query->radio_group(-name=>'srs_Email_List', -values=>['All
notices'], -default=>"@rows"),
'</td><td>',
$query->radio_group(-name=>'srs_Email_List', -values=>['Major
notices'], -default=>"@rows"),
'</td><td>',
$query->radio_group(-name=>'srs_Email_List', -values=>['No
email'], -default=>"@rows"),
'</td><tr>',


when i read this into the cgi script it comes back as a string. Any
ideas how to get around this?

In case you are wondering why html did not work - the @rows in the
above code is from a fetchrow_array and so would not check the right
radio button depending on the sql.

Thanks,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top