How to create a Perl debugger - linux

I wrote a bunch of functions for the Perl debugger, but every time I want to test them I need to do export PERL5DB="my code". Is there a way I can set it to a file and then use it?
I tried adding a file myperldb.pl in /usr/lib/perl/, but it doesn't allow me. That's because I am not the administrator user. So is there a workaround to it?

Make a copy of /usr/lib/perl/perl5db.pl in some other directory, change it to your heart's content, and debug your scripts with
perl -I/dir/that/contains/your/perl5db.pl/copy/ -d your_script.pl
The -I<dir> switch will get perl to look in the directory you choose to find libraries before it looks in its default directories.

That's what the .perldb file is for.

You may use this command:
PERL5DB="BEGIN{ require 'my_debugger.pm' }" perl -d script.pl
$cat my_debugger.pm
package DB;
sub DB {
}
sub sub {
print "$DB::sub called\n";
return &$DB::sub;
}
1;
You may find more information here.

Related

Linux command line open any directory

I'm currently using the Linux command line and was just wondering whether there is a quick command you can enter into the console to open any of a given directory.
I'll give you an example of what I mean.
say in a directory ligands/
we have:
ligand_1993324
ligand_1993444
ligand 1993255
shoe_lace
water_bottle
Lets just say there are 100000 of these very similar directories. Because I'm lazy I just want to pick any random one of these, but it has to begin with ligand_199 for example.
Please not I'm trawled through the manual and can't find anything, I've also looked at other stacks, any help would be great!
There are a couple of versions of a program called variously "randomline" or "randline" about. This version shows its age (it's in Perl).
#!/usr/bin/perl
while(<>)
{
push #lines, $_;
}
$randline = $#lines;
$randline = rand($randline);
print $lines[$randline];
Given this in a file ~/bin/randomline, then your task reduces to the following, assuming that you want to open the file with vim:
vim $(ls ligands/ligand_199* | ~/bin/randomline)
You can use following:
files=(/my/dir/*)
file=`printf "%s\n" "${files[RANDOM % ${#files[#]}]}"`
cat file
Maybe something like
number=$(((RANDOM%10000)+1)) && emacs -nw "ligand_199$number" ?

How do I set up a preload file for node?

Is there a way to preload some file before each time I run node (interactively), just like .vimrc, .bash_profile, etc.?
I use node mainly interactively, and I use the module CSV a lot, is there a way to avoid typing require('./csv') every time I start node?
Create an initialization file (for example ~/.noderc):
var csv = require('csv');
// put a blank line at the end of the file
Now add this line to your shell config (.bashrc / .zshrc / whatever shell you use):
alias nodei="cat ~/.noderc - | node -i"
VoilĂ !
#Ilan Frumer provided one way to do it. I think I'll give another choice here: build a REPL of your own.
From their documentation. You can find a way to write a repl of your own. You can add whatever scripts before and after the interations of it, and even use some advance API's.
For example, I created a file called .noderc.js under ~ as follows
repl = require('repl');
myFunc = function(){
console.log("Hello, there!");
};
repl.start("> ");
And you can go ahead and alias nodei="node ~/.noderc.js",
$ nodei
> myFunc()
Hello, there!
undefined

Shell script to change file name using for loop

I want to change file names in a folder in a way like this:
previous form new form
one-1 to VAS-M0001-001
one-2 to VAS-M0001-002
one-3 to VAS-M0001-003
one-4 to VAS-M0001-004
Can anyone please suggest me a good way to do that?
I would just use a simple loop:
for f in one-*; do mv one-$f VAS-M001-000$f; done
Of course, you can use printf to format the number better (if you have more than 9 files)
rename has such a functionality
[username#hostname aa]$ touch one-1 one-2 one-3 one-4
[username#hostname aa]$ ls
one-1 one-2 one-3 one-4
[username#hostname aa]$ rename one- VAS-M0001-000 one*
[username#hostname aa]$ ls
VAS-M0001-0001 VAS-M0001-0002 VAS-M0001-0003 VAS-M0001-0004

linux - export output from apachetop to file

Is it possible to export output from apachetop to file? Something like this: "apachetop > file", but because apachetop is running "forever", so this command is also running forever. I just need to obtain actual output from this program and handle it in my GTK# application.
Every answer will be very appreciated.
Matej.
This might work:
{ apachetop > file 2>&1 & sleep 1; kill $! ; }
but no guarantees :)
Another way using linux is to find out the /dev/vcsN device that is being used when running the program and reading from that file directly. It contains a copy of the screen data for a given VT; I'm not sure if there is a applicable device for a pty.
Well indirectly apachetop is using the access.log file to get it's data.
Look at
/var/log/apache2/access.log
You'll simply have to parse the file to get the info you're looking for!/var/log/apache2/access.log

CCNetConfig command line parameter for opening a ccnet.config?

I'm trying out CCNetConfig (warning, website a little slow). Great app, one annoyance.
I can see in the documentation and even in the source code (Look at the end of the Initialize method) that I should be able to pass in a command line parameter to automatically load the configuration file.
I have tried:
-f E:\CruiseControl.Net\server\ccnet.config
-file E:\CruiseControl.Net\server\ccnet.config
-f=E:\CruiseControl.Net\server\ccnet.config
-file=E:\CruiseControl.Net\server\ccnet.config
And the same 4 switches with quotes around the file name just in case.
They all produce errors or just don't work. Has anyone had success doing this?
Thanks in advance.
Try moving it to a different path. Try the simplest thing: c:\ccnet.config.
I'm guessing it's the source of the problem because I recall CCNetConfig gave me sh!t early on when I tried to open files in paths that had spaces in them (e..g in Program Files).
According to my version of CCNet the command line flag for using a different config file is -c or --config, so the following should do it...
-c "E:\CruiseControl.Net\server\ccnet.config"
...which works for me.
I don't know why it uses a non-standard flag, but there you go.

Resources