Tracing (for documentation purposes) through .cmd and .pl files. - perl

I am somewhat new to programming and VERY to command line and perl. I was wondering if anyone knew of a way that I can trace through a .cmd file and see what perl scripts its calling and then open those files and see what files it is calling (or functions etc...) without having to go through each file manually. I use Visual Studio 2010 and Notepad. I am mostly trying to do this to get everything documented and I would like to eventually be able to have a TOC or Tree View of the files and which files/commands/functions they call etc.. I am probably not explaining this well :) So, apologies AND Thanks in advance!! Britt

The perl debugger will let you step through perl applications/scripts and see what is getting used with various levels of detail. See perldoc perldebug or the online documentation for how that works.
Padre is a nice (and free) IDE for perl and you can look at other answers to this question for more ideas on how to use perl with VisualStudio.

Tracing batch file is problematic: Is there any way to trace through the execution of a batch file?
For tracing Perl programs, install Devel::Trace and set PERL5OPT=-d:Trace.

Related

"Save as" an open file from Command Line

I have a large folder of DWG files and want to convert them to DXF files, using Solid Edge. After opening the documents, is it possible to "Save As" from the command line or powershell?
Is this a program by program line of code or is it universal for all programs?
So if I wanted to save a .docx document open in Microsoft Word as a .pdf (for want of a better example) can I use that same line of code?
Any help appreciated...
Well since you want to convert from one Autocad format to another, you could do it using Autocad's command line.
https://knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/autodesk-customization-conversion-tools.html?_ga=2.88877275.1703552679.1574826072-7420195.1574826072
This does require you writing all of the scripting of course.
Alternatively, there is this handy scripted mass converter someone wrote using lisp and they wrote a custom script executor wrapper thingy but their scripting supposedly requires the full version of autocat (at least version 2010 to accomplish this.)
https://www.cadtutor.net/forum/topic/51941-autocad-mass-convert-dwg-to-dxf-batch-convert-dwg-to-dxf-mas-dwg-convert/
That said the official AutocCAD conversion command-line utilities are also going to use LISP scripting, so you might want to just take the second script, and work through it manually testing against the normal AutoCAD utilities until you can get it working for your needs to sort of jump start you.
If you do that I would suggest re-posting with tags for LISP and AutoCAD and give them a sample of what you have got if you end up going the official tools and your own or jump-started script route.
Hope that will be helpful to you and others in the future! :)
As commented beneath my question,
No, it would not be universal
So, no, there is no way of using a single command "save as" on every single program, and as Solid Edge doesn't have a command line API, that I know of, I would have to write a program for it.

how can i compare a .reg file with a windows registry using perl

Can I compare a .reg file with a Windows registry using Perl. If yes, how can I perform that?
I searched in several sites, but couldn't get a proper response.
Your help will be highly appreciated.
thanks.
Check the Win32::TieRegistry module.
If you're using ActiveState's ActivePerl, it will include a lot of the Windows packages that you need for things like registry reading, etc.
I recommend looking at Win32:Registry1 Win32::TieRegistry. You can look at a key in our .reg file (it's a text file), and then open that same key in the registry and compare the values. Take a look at the documentation.
Also, I believe registry files are in Windows INI file format. If that's the case, take a look at Config::IniFiles. This will help you read in your .reg file and go through it line by line. I've used it, and it's pretty simple to use. Config::IniFiles isn't a standard Perl module, so you have to download it from CPAN. However, ActivePerl comes with Config::Ini. I haven't used that one, but it looks like it might help.
1 I've been informed by Dmitry Mina that Win32::Registry is obsolete. I now see it says so in the documentation and the documentation recommends to use Win32::TieRegistry.

Integrating external highlighter tool in Eclipse editor

Okay, this is probably easy, but I don't know proper words to describe it, and hence, google it...
I have an external script which takes a file name and outputs this:
/path/to/file.py:683:80: E501 line too long (85 characters)
/path/to/file.py:690:21: other error message
..etc..
Now, I know this output format is widely accepted by other, much simple IDEs, e.g. EditPlus. I don't know how to integrate it with Eclipse though.
I want this script integrated with my editor windows. I want Eclipse to run it in the background, every time I save the file, and then parse the results and mark all the lines which occured in the script's output. It should look something like this:
How can I do that?
Note (for those who know why I need this): I know PyDev has a pep8.py checker integrated, but it's not enough.
Ok, so I implemented that plugin myself. I does exactly what I asked for, I guess. I made it configurable with some rude regular expressions.
I posted the code and installation instructions here (GitHub).
Your own plug-in that runs the script and examines its output can create Markers from that output. See http://www.eclipse.org/articles/Article-Mark%20My%20Words/mark-my-words.html .

Debugging perl CGI

I am using a web form I created as an interface to query a MySQL database. I have written some
perl CGI scripts to process the queries. But I am not getting the desired output, so I need to
debug the scripts. How do I do that? I mostly use Eclipse for debugging perl, but now I have the
web form parameters (checkboxes, listboxes) as input to the script. Is there any way I can pass
in the inputs from the web page and then debug the script in Eclipse? Or is there any other way
of debugging in this case? Hope I have made myself clear. Thanks.
I use this Perl module for CGI debugging. It lets you capture all data sent to a CGI script, when running from a normal browser. It then lets you "replay" the script from anywhere (command line, within a debugger) using the captured data.
CGI::Inspect looks promising, though I haven't tried it yet myself.
Using Devel::DumpTrace during a normal CGI session (with the data being logged to a file, via DUMPTRACE_FH) is a way to do in-depth debugging, without using an actual debugger.
Yes, of course you can use Apaches error log to do debugging; which a very lazy but efficient way to work.
You mention you use Eclipse so I assume you also use the EPIC plug-in for Perl development. Check out this chapter on how to configure Eclipse/EPIC for debugging CGI:
http://www.epic-ide.org/guide/ch06s02.php
I would hope Eclipse has a way to simulate CGI.
I use ActiveState's Komodo IDE, and it can simulate CGI (including input params), so I can recommend that as a good tool for this purpose. The IDE is NOT free, though, but consider this an investment if you're going to be doing this a lot. (I'm NOT affiliated with ActiveState - just a happy customer.)
It's not clear what exactly you want to debug, but a few tips:
When running under Apache, warnings go to the error.log, so you could follow your variables there.
The CGI.pm module allows you to run CGI scripts from the command-line (with parameters).
if you have a hypothetical CGI program written in perl, called webawesome.pl and you want to pass it two parameters: name and age, you can use a shell command like this:
prompt> perl -d webawesome.pl name=sifl age=21
Now you're in the perl debugger and you can step through your program, and the key/value pairs from the command line will be loaded as form parameters by CGI.pm
Setting these command line switches in Eclipse is left as an exercise to the reader, as I am an unabashed vi user, and haven't use eclipse in two or three years. I know there's dialogs to set run/debug options.
You can use Firebug or Fiddler to watch your requests made from the form, to ensure you are sending exactly what you think you are. You can also open a file open(fh,">>debug.txt") and print out the sql calls that you are making to a log file. I would also suggest learning about Data::Dumper which will print out objects prettily so you can see their structure.

How can I get emacs to chmod new files to executable if they have a certain extension?

I often write small perl scripts to solve various problem of to explore perl behavior.
I use templates for .pl files which is nice. it autopopulates the basics into my buffer.
A small annoyance is that whenever I do this, before running it, I have to
chmod ugo+x
Can I get emacs to do this automagically for me (based on the file extension)?
Of the solutions on the page to which Trey has linked, by far the best is:
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
I've been using this for many years and have almost never needed to make a script executable by hand in that time.
How about the solutions offered on this page, they key off the fact that the file begins with #!. There's also a package that does this, shebang.el (which I happen to use). You could easily change the code to make the condition that the file name extension be .pl, but looking for #! is probably more generic.