Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Wednesday, April 27, 2011

perl chomp backticks

When you use backticks in perl to get output from the system, you may end up with trailing newlines. I usually get rid of them with chomp.

Here is an example of getting the (base)name of the script being executed, from within the script.

chomp(my $SCRIPTNAME=`basename $0`);
I usually use the script name in the usage/help text of the script.

It is interesting to note that the parentheses are required, because if you did this:
chomp $SCRIPTNAME=`basename $0`

It would be interpreted as:
(chomp $SCRIPTNAME) =`basename $0`

which is not what you want.

Monday, March 28, 2011

install vmware tools without those annoying prompts

Every time I upgrade the kernel on my linux vm, I need to re-install vmware tools. This is painful, because vmware-install.pl is an interactive script. To make this process automated, you can use the following, poorly documented, command line argument:


$ sudo ./vmware-install.pl --default


This works sort of like apt-get's assume-yes (-y) command line argument, and it will automatically pick the defaults for all the interactive prompts.

It goes without saying, this won't work for you if you need to customize the install in any way.