Solved

Perl Sub with ok / cancel buttons - should be really simple...

Posted on 2006-07-04
2
227 Views
Last Modified: 2012-05-05
Hi All,

Ok i am really, really new to perl and could really do with some help on this.

I am writing a script which will have a number of subs all opened by links.

So for example:

sub test{

#Insert code here#
        }

Would be called by function:

                function test(){
                        $alert
                        var page="$script?action=test";
                        show(page, 110,370);
                }

And the link for this function would be:

<a href="javascript:parent.head.test()"></a> (The script is in frames)


So that how the script will operate.

I want this particular sub to find files in a directory and delete them depending on their name.

The script to do this is:

#!/usr/bin/perl
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

$word_to_delete = "pages";

print "content-type: text/html \n\n";      #The header
opendir (DIR,"/home/mysite.com/public_html/folder/");
@files = grep(/$word_to_delete/, readdir (DIR));
closedir (DIR);

foreach $file (@files)
{
      unlink $file;
      }
if (unlink($file) == 0) {
    print "File deleted successfully.";
} else {
    print "File was not deleted.";
}


Where i get stuck is when i execute the "delete script" on it's own, it will obviosuly instantly run and perform the operation.

What i want to do is insert this code into the "sub test" and add in an ok button.

So when you click the link

<a href="javascript:parent.head.test()"></a> the sub will open "show(page, 110,370);" and then you have the option to click ok and run the script.

So to sumarise,

I could do with someone posting the full sub test containing the "delete script" and adding in an OK button which once clicked will run the delete script.

Basically i am used to Javascript where you post the function in the header and then call it with a javascript link. So Perl is totally alien to me :-)


If anyone can post the full source for this sub i would be very grateful.

Regards

Harry.
0
Comment
Question by:harry_bela
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Perl_Diver earned 250 total points
ID: 17038786
this is not an answer to your question, which I really am not sure of what the question is, but this part of the perl code you posted is not correct:

foreach $file (@files)
{
     unlink $file;
     }
if (unlink($file) == 0) {
    print "File deleted successfully.";
} else {
    print "File was not deleted.";
}
 

it should be:

foreach $file (@files) {
   if (unlink $file) {
      print "File deleted successfully.\n";
   }
   else {
      print "File was not deleted.\n";
   }
}

also, you must either be in the directory that the files are stored in or $file must contain the full machine path to the files for the unlink() function to work.
0
 

Author Comment

by:harry_bela
ID: 17121796
Many thanks Perl_Diver that will point me in the right direction.

Cheers

Harry Bela
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

631 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