getopt on linux and solaris - solaris

On linux the following operation with getopt works fine:
TEMP=`getopt :mvfuhr:: --long "mask,verbose,force,unmask, help, remask::" -n 'test.sh' -- "$#"`
On Solaris, i am unable use the long arguments to process...
Though the this works:
TEMP=`getopt :mvfuhr:: "$#"`
Looks like the getopt bundled with the solaris is of an older version. How can i make it work like linux? or is there some setting that needs to be done to process long arguments?

Here is a clever (although currently with a minor bug) way to handle this issue:
Using getopts in bash shell script to get long and short command line options

Related

Is Perl slower when compiled with DDEBUGGING?

According to this slide from Supercharging Perl - Daina Pettit,
It reads,
Avoid versions of perl compiled with threading or DDEBUGGING unless you know you need them.
I know most distros compile Perl with threading, but my Perl on Debian (as observed with perl -V_ is compiled with -DDEBUGGING=-g does this slow it down?
Perl with debugging enabled is slower.,
Note that a perl built with -DDEBUGGING will be much bigger and will run much, much more slowly than a standard perl.
However, -DDEBUGGING=-g does not enable debugging:
As a convenience, debugging code (-DDEBUGGING) and debugging symbols (-g) can be enabled jointly or separately using a Configure switch, also (somewhat confusingly) named -DDEBUGGING. For a more eye appealing call, -DEBUGGING is defined to be an alias for -DDEBUGGING. For both, the -U calls are also supported, in order to be able to overrule the hints or Policy.sh settings.
and also documented:
Configure -DEBUGGING=-g
Adds -g to optimize, but does not set -DDEBUGGING. (Note: Your system may actually require something like cc -g2. Check your man pages for cc(1) and also any hint file for your system.)
You can test status with: perl -D, if you see the following you do not have -DDEBUGGING,
Recompile perl with -DDEBUGGING to use -D switch (did you mean -d ?)

Why does a MooseX::App app not know any commands on a different machine

I have written a midsized CLI application. Once I copied it to our development server I noticed it doesn't recognize or know any of its commands if run there. I minimized the code to the following example which works in my local machine but not on the server. What cloud be the reason?
package MyApp;
use MooseX::App;
1;
package MyApp::Yay;
use MooseX::App::Command;
sub run {print "yay\n"}
1;
package main;
MyApp->new_with_command->run;
1;
Save that in a file my_app.pl and call it like:
perl my_app.pl yay
Expected output:
yay
On the development server the little application doesn't accept yay as a command nor does it list any command in the help. The output looks like this:
Unknown command 'yay'
usage:
my_app.pl <command> [long options...]
my_app.pl help
my_app.pl <command> --help
global options:
--help -h --usage -? Prints this usage information. [Flag]
available commands:
help Prints this usage information
The software involved is:
local machine (working)
Perl v5.14.4
MooseX::App 1.30
development server (not working there)
Perl 5.10.0
MooseX::App 1.30
Unfortunately I cannot install different Perl versions on the development server but I doubt it's related to Perl itself. Update: It actually turned out that Perl 5.10.0 broke MooseX::App.
Does the program know the yay command when you execute it? Do you have any hint why it won't work?
5.10.0 was a fairly buggy version of perl. Try another version using perlbrew.

How to have Dexy evaluate Perl scripts?

The dexy documentation states than any language may be used. The tutorial use the py filter to run Python file, but I didn't find any filter to run Perl file.
I try to execute a very simple Perl file
I've tried to use the bash or sh filter, but with no luck, and didn't find any execute-or-like filter.
Am I missing something obvious ?
Ok, here are the different solutions I found about this.
1. A perl filter now exist
Ok, Ana is the owner of this project and is very reactive. I asked her the question about dexy and perl on IRC, and tada ! Less than 1 hour later, there was a commit on the repository with perl support.
So, if you just get latest version and install it this way :
git clone https://github.com/dexy/dexy
cd dexy
sudo pip install -e .
You should have a perl filter.
If you want to pass arguments to a script, just use the scriptargs setting.
2. Use a bash script
Another very simple solution is to embed the launch of a perl script into a sh/bash script, and use the sh/shint/bash filter that already exist.
3. Use bash script without additional files
If you fear that the latest solution will makes you add a lot of tiny scripts in your directories, you may use the contents feature of dexy. That way, the required one-liners are defined in dexy.yaml only.
Something like :
- shell-myscript.sh|sh:
- contents: "perl ./perl/myscript.pl --any-parameter"
- perl/myscript.pl
is doing the job just fine for me.

call application command from specific mojolicious installation

I need to call my own mojolicious command from command line, using specific mojolicius intallation (System version of mojolicius is too old, and I can't update it).
How can I do this?
something like:
$ ./kraih-mojo-97e88d1/script/mojo my_app/script/my_app my_command
will be great!
For quick-and-dirty solution try adding use lib '/path/to/kraih-mojo-97e88d1/lib'; statement to your my_app script and run command as
perl my_app/script/my_app my_command
If you want to do a similar thing to the answer by melhesedek, but without changing your code, try using the -I switch to the perl interpreter:
perl -I/path/to/kraih-mojo-97e88d1/lib my_app/script/my_app my_command
or you can use the PERL5LIB environment variable, which you could set in your local environment, or prefix the command, like so:
PERL5LIB=/path/to/kraih-mojo-97e88d1/lib ./my_app/script/my_app my_command
Also, I personally believe that the lib module is too magical for my taste. It's not readily apparent in every-day use, but it should NEVER be used in say CPAN code. Just fyi.

Is there a CPAN Perl module to find total/used/free memory on a host (without running command line through a system() call)?

Is there a CPAN Perl module which provides total/used/free memory (like vmstat does) on a host without running a command line through a system() call to get the info?
Ideally it should be cross-platform (Linux and Solaris) though please provide Linux or Solaris-only ones as well.
Looks like Sys::MemInfo is what I needed.
It is implemented in XS, using <sys/sysinfo.h> for Linux and <sys/stat.h> / <sys/swap.h> for Solaris.
Try the Sys::Statistics::Linux distrubition for linux.