Thursday, 13 June 2013

Failed to install CPAN Perl module(s) LWP::UserAgent

Today I stuck in this error when recompiling php using easyapache. It was giving error to fail to install the given perl module.

-- Begin opt 'CurlSSL' --
!! Failed to install CPAN Perl module(s) LWP::UserAgent !!

Failed to install CPAN Perl module(s) LWP::UserAgent
When i check it using cpan , It says that this module is already installed and up to date. 

I tried different solutions to check why it is not getting installed.

Some on them was using cpan


root@server [~]# cpancpan>cpan> install  LWP::UserAgent
CPAN: Storable loaded ok (v2.20)
Reading '/home/.cpan/Metadata'
  Database was generated on Thu, 13 Jun 2013 21:53:03 GMT
CPAN: Module::CoreList loaded ok (v2.18)
LWP::UserAgent is up to date (6.05).
I even tried opening a support ticket but could not process free cpanel ticket due to some error .

Solution:

Then i tried to uninstall the given perl module so i can re-install it. Inorder to un-install the perl module I downloaded cpanminus.


curl -L http://cpanmin.us | sudo perl - App::cpanminus
sudo cpanm LWP::UserAgent
Then I run the command to uninstall the perl module using


 cpanm -U LWP::UserAgent
and then installed the module again using
 root@server [~]# cpan
cpan>
cpan> install LWP::UserAgent

And then run easyapache again and it all went successfully.. So writing this so some one might get benefit of it.

Thanks
Asif

Friday, 25 May 2012

sum of one key/column of multi dimentional array

Some time we need to get sum of one key/column of a multdimentional array and need unique output similary to aggregated and grup by functions of mysql functions, here i have written a php function, this is my first post , so please tell me about this and if you can give a better algo for this, please share. I tried searching online but could not find one.

thanks

------------------------------------------------------------------------------------------------------------------------


function sumArraykey($array,$key){
 foreach($array as $first){
                $first[$key]="";
                $distinct[]=$first;
        }

        $unique = array_map("unserialize", array_unique(array_map("serialize", $distinct)));
        foreach($unique as $first){
                $sum=0;
                foreach($array as $second){
                        $val=$second[$key];
                        $second[$key]="";
                        $matchcounter=1;
                        if($second == $first){
                                $matchcounter++;
                                $sum+=$val;
                        }
                }
                $first[$key]=$sum;

                $return[]=$first;
        }
        return $return;
}
------------------------------------------------------------------------------------------------------------------------
Example use!!!


$test[]=array(0=>1,1=>2,2=>3,3=>4,4=>5,5=>6,6=>10);
$test[]=array(0=>1,1=>2,2=>3,3=>4,4=>5,5=>6,6=>10);
$test[]=array(0=>1,1=>2,2=>3,3=>4,4=>5,5=>6,6=>10);
$test[]=array(0=>3,1=>2,2=>3,3=>4,4=>5,5=>6,6=>10);
$test[]=array(0=>3,1=>2,2=>3,3=>4,4=>5,5=>6,6=>10);

$output=sumArraykey($test,6);
print_r($output);