I've been searching all over the internet to simply do the following:
$tempfile = "/usr/school/tempfile.dat";
$myvar = param('add'); ###add is the variable assigned to a popup menu
`ls -l $myvar * >> $tempfile` ###I also tried `ls -l ${myvar}* >>$tempfile`
open(ADDLIST, "<tempfile");
@addvar = (" ", <ADDLIST>, $myvar);
unlink("$tempfile");
return @addvar
Lets say if $myvar = "ab"
the output lists all the contents of ls -l and the string ab. But what I want is to see the list of ls -l ab* and the string ab.
unforutunatly nothing comes up, not even the "my variable" part
I tried the following
$myvar2 = "abcdefghi";
`echo my variable two is $myvar2 >> $tempfile`;
and it comes up in the array.
so my question is, how can I gather the exact word the 'add' popup menu is selected on?
if you look at the array @addvar, the entry $myvar (which equals to param('add')) comes up, however when used in the backquoted string it doesn't work. Can someone please clarify why this is. Many thanks.
So the output will not be automatically printed. You have to print() it.
For the rest of your question, I do not quite understand the exact question you have. I have tried executing ls -l with wildcards with backticks but it is working. Please consider rephrasing your question and give us further elaborations.
ok my real work does not involve wildcard or anything, the following is what I am doing:
I am making webpage using cgi, I have a popup menu named "add" and in the menu it has a list of filenames.
In each of these files that are listed, there is another list containing information on a network. These files are updated daily.
so I made a submit button, when it is pressed; right next to it a new popup menu appears. The contents in the popup menu is the list of network data stored in file that was first selected on the "add" popup menu.
So my biggest dellima is to find out what filename was selected in the add popup menu. Than I want to use the filename, put it into a directory format than access it and using pg for example I would gather all the network information. From there I put the network information in an array and refrence it to the new popup menu under the -value item.
So right now this is something similar to what I am doing:
i suggest you use perl's native method of listing files eg readdir(), opendir()...instead of calling external shell commands. You can use format to format your output. For more info: perldoc -f opendir, perldoc -f readdir , perldoc -f format
Then this is more of a Perl CGI question. It sounds like it has nothing to do with backticks at all, so have you put in some debug statements to test if $myval2 is always empty or actually contains the value you expect as you run it in browser? I suppose you are referring to a form parameter 'add' retrieved via CGI->param() method. In case this is true, as I do not see the HTML which triggered the CGI script in action, it will be impossible to tell what the problem could be. The HTML (or in more complex cases, Javascript) will certainly affect how form parameters are being sent. So, to create a Web-based application, you cannot blindly use Perl (or other language)'s API to generate controls without understanding HTML, and you must verify the generated HTML to ensure they work in the way you expect.
Hopefully I did not misunderstand your question, but I guess you should probably look up some primer on CGI programming to help you get a more concrete idea of what you need to do.