Saturday, January 12, 2013

Use Notepad++ as Perl IDE

If you are looking for a fast and small in size text editor as Perl IDE, Notepad++ probably one of the best choice. By default, Notepad++ will not run Perl script within the editor, you need install and configure "NppExec" plugin to allow this.
Follows the below steps:
  1. Install "NppExec" from "Plugin Manager".
  2. After installed the plugin, from "Plugins" menu, choose "NppExec" -> "Execute...".
  3. Copy the following script and click "Save..." to save it as "Run Perl". Click "OK" to close the dialog.
    NPP_SAVE
    cd "$(CURRENT_DIRECTORY)"
    C:\perl\bin\perl "$(FILE_NAME)" 
  4. From "Plugins" menu, choose "NppExec" -> "Advanced Options...".
  5. Check "Place to the Macros submenu" which allows us to execute the script from "Macros" menu.
  6. Type "Run Perl" in "Item name" text box and associate it with "Run Perl" script, and click "Add/Modify" to create it. menu item. Click "OK" to save the settings.
  7. Now, assign a shortcut key e.g. "Ctrl+Shift+B" to execute the script. From "Settings" menu, choose "Shortcut Mapper" -> "Plugin commands" tab, select "Run Perl" and click "Modify" to assign "Ctrl+Shift+B" or any preferable key. Click "OK" to save it.
  8. Restart Notepad++.
  9. After restarted, you can execute an opened Perl script by pressing "Ctrl+Shift+B". 

29 comments:

  1. Hey thanks for this blog post. I was going to use Eclipse or Padre but both are hard to configure and buggy. Notepad ++ is proven and works great so this will help a lot. I got it up and running in min.

    ReplyDelete
  2. Awesome. I used to use TextPad for my Perl scripts in Windows because it supported running programs out of the box, but Notepad++ is a lot more powerful. So, cool. :-)

    ReplyDelete
  3. If you use strawberry perl you need use this script:

    NPP_SAVE
    cd "$(CURRENT_DIRECTORY)"
    C:\strawberry\perl\bin\perl "$(FILE_NAME)"

    ReplyDelete
  4. Any idea why I can not run Perl in debug mode using this approach?
    When I change the command, adding the -d, it fails.

    ReplyDelete
    Replies
    1. Change the Notepad++ command to:

      NPP_SAVE
      cd "$(CURRENT_DIRECTORY)"
      NPP_RUN C:\perl\bin\perl -d "$(FILE_NAME)"

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi Guys,

    **Please note that the Path is changed when installing notepad++ 64 bit.

    NPP_SAVE
    cd $(CURRENT_DIRECTORY)
    C:\Perl64\bin\perl $(FILE_NAME)

    Cheers,

    Jay

    ReplyDelete
  7. thankyou so much..thats amazing!!

    ReplyDelete
  8. Thanks for this. Using instructions elsewhere I was getting an "Invalid argument" error when trying to execute a script. It didn't like the full path to the script. Using "cd $(CURRENT_DIRECTORY)" solved it.

    Apparently, you cannot use something like "perl c:\tmp\myscript.cgi" as an argument. You have to cd to the script directory first then execute it with "perl myscript.cgi"

    ReplyDelete
  9. Thanks so much for the post but when we execute perl script will I get the following everytime? .. sorry I am a newbie

    NPP_EXEC: "Run Perl"
    NPP_SAVE: C:\Users\k\Desktop\Perl_scripts\1.pl
    CD: C:\Users\k\Desktop\Perl_scripts
    Current directory: C:\Users\k\Desktop\Perl_scripts
    C:\Perl64\bin\perl "1.pl"
    Process started >>>
    Just Started scripting today - Thu Jul 10 21:42:05 2014<<< Process finished. (Exit code 0)

    ReplyDelete
    Replies
    1. You can disable the internal messages:

      From "Plugins" menu -> NppExec -> Check "No Internal Messages".

      Delete
  10. Awesome post , Instructions and snapshots are very clear to understand.

    Every time i execute ,i get an (EXECUTE ) dialogue box opened , with Commands

    NPP_SAVE
    cd $(CURRENT_DIRECTORY)
    C:\Perl64\bin\perl $(FILE_NAME)

    I need to click on OK eveytime to execute the program.

    Is there any way we can avoid it ?

    Thanks in advance....

    ReplyDelete
  11. thank you so much for this excellent post! I am now able to execute perl scripts through notepad++

    ReplyDelete
  12. Work nice but I can't "use warning" (probably a problem of my own?).
    Thx anyway,
    Paul.

    ReplyDelete
  13. Thank you!! When running the perl script shown, why does my result pop up in a DOS window instead of the Console section in Notepad++ like yours?

    rp672u

    ReplyDelete
  14. I'm using notepad++ in ubuntu, unable to get output, it is giving something like
    NPP_EXEC: "Run Perl"
    NPP_SAVE: Z:\home\vinodv\webcrawal\nptest.pl
    CD: Z:\home\vinodv\webcrawal
    Current directory: Z:\home\vinodv\webcrawal
    /usr/bin/perl "nptest.pl"
    Process started >>>
    <<< Process finished. (Exit code -1)
    ================ READY ================

    ReplyDelete
  15. After updating np++, I had to enter all of this again. Is that normal?

    ReplyDelete
  16. Not able to see the command "Run Perl" in the shortcut mapper under plugin category.
    How to get a shortcut for run?

    ReplyDelete
    Replies
    1. Hi, I have the same issue. I tried installation with and without %APPDATA% options, but with the same result :(

      Delete
  17. I get an error where when I run the script It says Access is Denied in the console box
    Any Ideas

    ReplyDelete
  18. I am able to execute it, but how put break points and debug code using watch window

    ReplyDelete