Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Nov 042010
 

Pass hash as list in Perl

Answer:

To pass a hash as a list in Perl function, use the following way:

use strict;
use warnings;

sub foo {
    my %h = @_;
    print $h{1}; 
}

foo ( 1 => "One", 2 => "Two" );

One will be printed out.

Nov 032010
 

Optimize table in MySQL

Answer:

OPTIMIZE TABLE command is useful to defragment the database tables. It is particularly useful when you have deleted a large portion of a table or if you have made massive changes to a table with variable-length rows.

To do so, execute the following statement

mysql> OPTIMIZE TABLE my_table;

That's all.

Nov 022010
 

Empathy cannot connect to MSN

Answer:

To solve the problem of cannot connect to MSN using Empathy

1. Open the following file to edit:

gksudo gedit /usr/share/pyshared/papyon/service/description/SingleSignOn/RequestMultipleSecurityTokens.py

2. Find the following line...

CONTACTS = ("contacts.msn.com", "?fs=1&id=24000&kv=7&rn=93S9SWWw&tw=0&ver=2.1.6000.1")

3. Replace the line by

CONTACTS = ("contacts.msn.com", "MBI")

Close and restart Empathy should work.

Nov 012010
 

Force Perl to use integer arithmetic

Answer:

To force Perl to use integer arithmetic, instead of floating point, you just need to add the statement "use integer;" at the beginning of your script.

Example:

use strict;
use warnings;
use integer;

my $i = 10/3;
print $i; 

It above program will print out 3 instead of 3.333..

Oct 302010
 

Return the last evaluated statement from function in Perl

Answer:

By default, Perl does not require you to explicit return the the last evaluated statement from function.

E.g.

print function1();

sub function1 {
    my $i = 99;
}

The above program will output 99, and you can see the return statement is not needed and it is a valid Perl program.