Get array size in Perl
Answer:
To get the size of array in Perl, you have two methods.
Sample code:
my @a = (1, 2, ,3);
1. By scalar context
my $size = scalar @a;
2. By special variable $#array
my $size = $#a + 1;
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Get array size in Perl
Answer:
To get the size of array in Perl, you have two methods.
Sample code:
my @a = (1, 2, ,3);
1. By scalar context
my $size = scalar @a;
2. By special variable $#array
my $size = $#a + 1;
How to validate the format of a XML file in Linux?
Answer:
You can use xmllint, which came as part of the libxml2-utils package.
To install
# sudo apt-get install libxml2-utils
To validate the format of XML document
# xmllint --noout file.xml
How to print the current stack backtrace in Perl?
Answer:
To print out the current stack backtrace in Perl, just insert the following code in your script and it will print out the stuff you need.
use Carp qw(cluck);
cluck "This is how we got here!";
How to check current PHP version in PHP?
Answer:
If your PHP version is after PHP 5.2.7, you can use the PHP_VERSION constant.
echo PHP_VERSION;
Else, you can use the function phpversion()
echo phpversion();
New way to print in Perl6
Answer:
In Perl 6, you can use the new syntax say to print out string in Perl.
say 'hello';
But they are also valid under Perl 5.10 or 5.12, if you add
use feature qw(say);