Archive

Archive for the ‘Perl’ Category

Quick Perl Interview Points

May 4, 2012 Leave a comment

Some years ago when I was planning for job change one of my close friend Deepak told me if you want to crack Perl interview just revise these points. I called these as bullet points.

Just revising these points for my reference and for your help.

This is no particular order and written as mentioned by him over the phone :)

  • Referencing – de-referencing of data types – scaler, hash, array
  • pack – unpack
  • string – split. while,
  • pop,push,shift,unshift
  • array – add variable..
  • hash print
  • data read from hash.
  • sorting – numeric or normal
  • file handing
  • DB connection.
  • path module.
  • use warning, use strict, dbi, cgi, dump
  • perl mysql connection
  • regular expression – all small example
  • adding module how to..
  • use
  • require
  • my or local diff.
  • package
  • why we use 1 in package.
  • little oops in perl
  • @ISA
  • command line in perl
  • /usr/bin/perl
  • CGI T
  • use dignostic
  • how to debug
  • perl -d
  • cpan to cgi.
  • pass by value , pass by reference
  • environment variable
  • data type of return value.
  • how to know that array has unique value
  • how to run system command from perl, how many ways. 4-5 ways. diff between each
  • spacial variable
  • comments in regular expression
  • what are the default error
  • what is slurp mode
  • file hander, opearion, third argument
  • how to escape
  • apache
  • sorting – numeric or normal
  • regular expression – all small example
  • adding module how to..

I will keep adding new point as and when I will get.
Comment your points.

Happy Perl.

How to get Google Page-Rank from Perl Script

October 29, 2010 7 comments

Today got good package by which directly we can get the google page rank.

This is the easiest way to find the google page rank from Perl Code.

I tried this code in 2 ways
1. By list in the code
2. By putting the site from command prompt.

#!/usr/bin/perl
use warnings;
use strict;

use WWW::Google::PageRank;
my $pr = WWW::Google::PageRank->new;

my $page = $ARGV[0];

my @sites = (
  'http://www.yahoo.com',
  'http://www.wordpress.org',
  'http://www.wordpress.com',
  'http://www.labnol.org'
);
if(!$page) {
  foreach(@sites) {
	  print "$_ : ";
	  print scalar($pr->get($_)), "\n";
  }
} else {
  print "$page : ";
  print scalar($pr->get($page)), "\n";
}

2 Ways to run this code

ankur@ankur:~> perl googlerank.pl
http://www.yahoo.com : 9
http://www.wordpress.org : 9
http://www.wordpress.com : 9
http://www.labnol.org : 6
ankur@ankur:~> perl googlerank.pl http://www.apple.com
http://www.apple.com : 9
ankur@ankur:~>

This is the simplest code, we can change based on requirement.

Happy Perl.

Perl CPAN Reconfigure urllist

August 20, 2010 Leave a comment

Perl CPAN Reconfigure urllist

To push multiple URL to use CPAN :

conf urllist push url1 url2 url3

To remove first in urllist :

conf urllist shift

To remove last in urllist :

conf urllist pop

To commit your changes :

conf commit

happy programming.

POST a Multipart request in Perl via LWP

August 19, 2010 1 comment

Today I wrote good script which called the 3rd party API and for that I need to send a wav file via multipart.
I worte the code in Perl, which read my keyword via (param) and then I call my API and send the file via multipart.

#!/usr/bin/perl
print "Content-type: text/html\n\n";

use HTTP::Request::Common;
use LWP::UserAgent;
use CGI qw(:standard);
use strict;
use warnings;

my $file, $result, $message;
my $filePath = '/srv/www/cgi-bin/files';

$file = $filePath.'/'.$keyword.".wav";

my $ua = LWP::UserAgent->new;
my $req = $ua->request(POST 'http://www.yourURL',
	      Content_Type => 'form-data',
	      Content => [
		foo => "$foo",
		bar => "$bar",
		Upload => ["$file"]
	      ]
);

print "\nRESPONSE -- \n" . $req->as_string;

# Check the outcome of the response
if ($req->is_success) {
    print $req->content;
}
else {
  print "\n in else not success\n";
}

More links to read :
http://www.perlmonks.org/index.pl?node_id=186591
http://search.cpan.org/~gaas/libwww-perl/lib/HTTP/Request/Common.pm

Happy Programming.

Follow

Get every new post delivered to your Inbox.