Hi there,

I'm trying to open up a text file read info from it, alter it and write back the alterations when a user clicks on the save button, but I've hit two issues:-

1) I can't open the file for write access as I don't have permissions - can I alter a files permissions during a program using chmod? I've tried to alter it by hand in an ftp window (to 755 from 666) but it just stays the same.

2) A button (in perl) calls a java function only as far as I can find out, can I use it to call a perl function instead? if so could I have an example like this:-

print "<button type=button onClick=\"update_file()\">Save1</button>";

update_file() being the perl sub that I'd like to call.

If I can't do this and have to call a java function can I then call the perl sub from there instead, I've tried it like this but it doesn't do anything so I'm presuming it doesn't work:-

print "function update_file ()\n";
print "{";
print "update_input_filehandle_with_local_text ()";
print "}\n";

many thanks in advance for your help

javascript and perl are two entirely different things. Perl has no concept of javascript and the same is true in reverse. What you need to do is a send some data to your perl script via a CGI form and use that data to tell your perl script what to do, like run a certain subroutine in your perl script.

As far as the chmod goes, it is possible to change file permission with perl, use perls chmod function.


ah ok so java and perl can relate to the CGI form. So I could say have the button call a java function that sets a variable to true that is being checked by a while loop and when found to be true call the perl sub? is that the sort of thing you mean?

many thanks

javascript can only communicate with the perl script via the form. Do whatever you want with the javascript, but it has to set a form field to some value and then send the form data back to the perl script to process the data. Perl then accepts the data, processes it, and sends data back to the browser. But there is never any direct interaction between perl and javascript, they operate in two different environments, they can only communicate via the form.

Perl can print javascript while it outputs html back to the web browser and fill in javascript code with whatever data is needed by the javascript to run in the web browser, but once perl outputs the html/javascript code to the web browser it has no concept of what occurs after that until some form data is sent back to the perl script via the form.

There is also AJAX which is a blending of javascript and CGI scripting, but the process is essentially the same as described above although the interaction in the web browser looks different.

That's a great help thanks very much - I've nearly sorted it now :)


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.