The target is to run the following command line from within Eclipse on my currently opened file and refresh it to see the results:
perl -S -pi.bak myscript.pl
I am going to use an External Tools configuration.
this guide is based on Eclipse 3.7.1
- Open Run -> External Tools -> External Tools Configuration ...
(Alternatively you can open it from the Run icon with the small red toolbox on the corner)
- Select Program
- Add a New Launch Configuration (First Icon with the little plus on the top right corner or right click on Program -> New)
- You should see this:
- Fill the Name
- On the location put the path to the tool you want to launch (in this case perl: C:\Perl\bin\perl.exe)
- In the working direectory choose from the Variables..., ${container_loc} which is the directory of the file currently on the IDE
- As arguments put: -S -pi.bak ${file_prompt:Select Perl Script:D:\marcelo\Perl\bin\myscript.pl} ${container_name}
Again you don't have to type ${container_name} or ${file_prompt...} you can choose it from Variables...
- Press Apply
You should see this now:
- Go to the Refresh tab and check Refresh resources upon completion and choose from the options The selected resource
- Go to the Build tab and uncheck Build before launch
We are done, now several notes:
- In the Common tab you can check External Tools under Add to favorites menu and your script will appear on the External Tools submenu, without having to run it first.
- You probably noticed there are a lot of other options, feel free to experiment
- This example just modifies the file in the IDE. The contents of myscript.pl are:
next unless /Log.i/;
s/\bint\s+(\w+)/int n_$1/g;
s/\bString\s+(\w+)/String s_$1/g;
- The ${file_prompt:Select Perl Script:D:\marcelo\Perl\bin\myscript.pl} opens a dialog box where you can select the perl script to run.
- If you want to run always the same script just replace the ${file_prompt...} with the script name
I installed the EPIC plugin on Eclipse so I can edit perl files as well
You are not constrained to modify you resource. You can just run a script that generates outputs from the current file. The output of the script, also any errors encountered, are displayed in the Console
Tip: In perl if you want to both write the new file out and also print out a message for the user, use STDERR to print out the message and STDOUT to print out the file.