Saturday, January 31, 2009

Twitter and tag cloud

I have been playing with the blog template recently, while figuring out how to move on with the RankSearch project.
You will notice two visible changes to the right-hand side of this blog:
  1. A link to my twitter profile
  2. Added a tag cloud in replacement of the list
Some other changes that are not visible:
  1. Added my blog's feed automatically to twitter and identi.ca thanks to twitterfeed.com
  2. Played with my feed's settings to redirect all post feed traffic to FeedBurner
The twitter button was taken from here among a huge selection of templates.

The tag cloud was set in place thanks to frivolous motion's excellent post. It doesnt add a title by default but the solution was in the comment section. Just make sure to select the right line containing

and add just after it:



The "includable" line in question is the one right after the html tag for your tag cloud widget:
Make sure you have checked the "Expand Widget Templates" box in the Edit HTML page.

French expression of the day:
"C'est mon petit doigt qui me l'a dit": a little bird told me (litt. My little finger told me)

Next posts:
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install and use Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

Twitter and tag cloud

I have been playing with the blog template recently, while figuring out how to move on with the RankSearch project.
You will notice two visible changes to the right-hand side of this blog:
  1. A link to my twitter profile
  2. Added a tag cloud in replacement of the list
Some other changes that are not visible:
  1. Added my blog's feed automatically to twitter and identi.ca thanks to twitterfeed.com
  2. Played with my feed's settings to redirect all post feed traffic to FeedBurner
The twitter button was taken from here among a huge selection of templates.

The tag cloud was set in place thanks to frivolous motion's excellent post. It doesnt add a title by default but the solution was in the comment section. Just make sure to select the right line containing

and add just after it:



The "includable" line in question is the one right after the html tag for your tag cloud widget:
Make sure you have checked the "Expand Widget Templates" box in the Edit HTML page.

French expression of the day:
"C'est mon petit doigt qui me l'a dit": a little bird told me (litt. My little finger told me)

Next posts:
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install and use Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

Wednesday, January 28, 2009

CPAN, or how to get your project jump-started

CPAN
CPAN is not a TV channel about politics, nope.
It stands for Comprehensive Perl Archive Network.

It is a gold mine where you can dig amongst close to 15,000 Perl modules. No need to reinvent the wheel, you're very likely to find a module that suits your need in CPAN.
This archive is one of the strength of the Perl community. Most of the modules are open-source and you can scan through 20,000,000 lines of code. There is great material there for beginners to chew on!

The Strawberry Perl distribution includes a full tool chain to install Perl modules from CPAN (as you would do from Linux). This is the main difference with ActivePerl.
ActivePerl allows you to go through its PPM (Perl Packet Manager) system to install pre-compiled modules. You can also download CPAN source code and compile it yourself but you will have to deal with the dependencies yourself.

When installing a module from CPAN, you will automatically pull all dependencies on that module as well, making your install as easy as typing cpan at a DOS prompt.
This will open the cpan shell. Typing help will display all possible commands.
If you know the name of your module, just type install ModuleName and let the process run its course.

RankSearch
CPAN is the place where I'll start in order to investigate core functionalities for the RankSearch.pl script (for http requests and html parsing).
I posted on the Websearch Help forum to see if anybody could answer the question about RankSearch.pl violating Google's terms of service.

French expression of the day:
Deep snow in the Winter, tall grain in the Summer: "Janvier rigoureux, an très heureux" and "Vaut mieux voir un chien enragé que soleil en janvier." (litt. Better see an enraged dog than sun in January)

Next posts:
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

CPAN, or how to get your project jump-started

CPAN
CPAN is not a TV channel about politics, nope.
It stands for Comprehensive Perl Archive Network.

It is a gold mine where you can dig amongst close to 15,000 Perl modules. No need to reinvent the wheel, you're very likely to find a module that suits your need in CPAN.
This archive is one of the strength of the Perl community. Most of the modules are open-source and you can scan through 20,000,000 lines of code. There is great material there for beginners to chew on!

The Strawberry Perl distribution includes a full tool chain to install Perl modules from CPAN (as you would do from Linux). This is the main difference with ActivePerl.
ActivePerl allows you to go through its PPM (Perl Packet Manager) system to install pre-compiled modules. You can also download CPAN source code and compile it yourself but you will have to deal with the dependencies yourself.

When installing a module from CPAN, you will automatically pull all dependencies on that module as well, making your install as easy as typing cpan at a DOS prompt.
This will open the cpan shell. Typing help will display all possible commands.
If you know the name of your module, just type install ModuleName and let the process run its course.

RankSearch
CPAN is the place where I'll start in order to investigate core functionalities for the RankSearch.pl script (for http requests and html parsing).
I posted on the Websearch Help forum to see if anybody could answer the question about RankSearch.pl violating Google's terms of service.

French expression of the day:
Deep snow in the Winter, tall grain in the Summer: "Janvier rigoureux, an très heureux" and "Vaut mieux voir un chien enragé que soleil en janvier." (litt. Better see an enraged dog than sun in January)

Next posts:
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

Monday, January 26, 2009

RankSearch - The end already?

A friend at work informed me that the script that I have in mind for RankSearch might violate Google's Terms of Service.
I did some research and it looks like he's right. From Google's ToS:

Automated queries

Google's Terms of Service do not allow the sending of automated queries of any sort to our system without express permission in advance from Google. Sending automated queries absorbs resources and includes using any software (such as WebPosition Gold™) to send automated queries to Google to determine how a website or webpage ranks in Google search results for various queries.

What's your take on that? If RankSearch is implemented as a sequence of http queries, will it violate the ToS? This could get DamienLearnsPerl banned (I would get my life back!).
On the other hand, the amount of queries would be really low...
I looked for an email address to contact Google to ask the question but couldn't find any. Will look again tomorrow.

French expression of the day
"Chat échaudé craint l'eau froide": once bitten, twice shy (litterally: scalded cat fears cold water)

Next posts:
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

RankSearch - The end already?

A friend at work informed me that the script that I have in mind for RankSearch might violate Google's Terms of Service.
I did some research and it looks like he's right. From Google's ToS:

Automated queries

Google's Terms of Service do not allow the sending of automated queries of any sort to our system without express permission in advance from Google. Sending automated queries absorbs resources and includes using any software (such as WebPosition Gold™) to send automated queries to Google to determine how a website or webpage ranks in Google search results for various queries.

What's your take on that? If RankSearch is implemented as a sequence of http queries, will it violate the ToS? This could get DamienLearnsPerl banned (I would get my life back!).
On the other hand, the amount of queries would be really low...
I looked for an email address to contact Google to ask the question but couldn't find any. Will look again tomorrow.

French expression of the day
"Chat échaudé craint l'eau froide": once bitten, twice shy (litterally: scalded cat fears cold water)

Next posts:
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

Sunday, January 25, 2009

RankSearch - Part II: parsing the Perl command line

RankSearch: The design
The design of our little script is laid out in the comment header from last post:

1. Get the parameters from the user
  • In a first version, ensure that all parameters are filled
  • Later, we can provide a default value for the search engine (Google)
  • Or even display all the results for a list of supported search engines
2. Launch an http request with the parameters given by the user
  • Spawn a process able to communicate back to our script
  • It will probably be in the form of "http:\\$engine-blabla-search_criteria-moreblabla"
  • Need to investigate different urls for different search engines
3. Parse and display the results transmitted by the http process
  • Search for the target URL
  • Keep track of rank count
  • Launch new http request with updated page number if target not found
  • Display result to user
Today, I'll strike off the first item of the list. Time to get interactive!
In order to ease the handling of user input, I discovered that Perl includes the Getopt::Long module by default. The link on CPAN will show you all possible uses of the module.
One must be careful not to omit the "\" character before the variable name (like I did at first).
We'll only use string (character chain) inputs:
use Getopt::Long;
GetOptions (" engine="s" => \$SearchEngine);
This will store in $SearchEngine the parameter entered from the following perl command line:
perl "$(FULL_CURRENT_PATH)" --engine www.google.com --target damienlearnsperl.blogspot.com --keyword "learn perl"
or
perl "$(FULL_CURRENT_PATH)" -engine www.google.com -target damienlearnsperl.blogspot.com -keyword "learn perl"
or even
perl "$(FULL_CURRENT_PATH)" -e www.google.com -t damienlearnsperl.blogspot.com -k "learn perl"
(provided you only have one entry in Getoptions starting with "e")

Here's the script:
#!/usr/bin/perl -w
# --------------------------------------------------
# File : RankSearch.pl
# Author : DLP
# Date : January 24th 2009
# Object : Looks in a search engine what is the rank
# for a given website and a given keyword
# Input : - Search engine URL, eg. "www.google.com"
# - URL of website to monitor
# - Search expression to investigate
# Bugs : None
# To do : - Launch http request
# - Read html result
# - Analyse result and display website rank
# --------------------------------------------------
use strict;
use Getopt::Long; #Load module

# Global variable
my $PROG_NAME = "RankSearch";
my $VERSION = "v0.0.1";
my $PROG_DATE = "January 24th 2009";

# --------------------------------------------------
# Main program
# --------------------------------------------------
# More global variables
my $SearchEngine = "";
my $TargetURL = "";
my $Keyword = "";

#Parse command line arguments
GetOptions ("engine=s" => \$SearchEngine, #string
"target=s" => \$TargetURL,
"keyword=s" => \$Keyword);

# Check user input
if ($SearchEngine eq "" ||
$TargetURL eq "" || $Keyword eq "")
{
print "
You must enter a valid string for:
--engine = search engine URL
--target = the target of the search
--keyword = the search criteria
";
exit;
}

print "
$TargetURL is ranked nth on the $SearchEngine
search engine for the \"$Keyword\" criteria.";

__END__
Jan 24 2009 (0.0.1): first version of RankSearch
Jan 25 2009 (0.0.2): get params from command line

After getting the parameters, we check to see if anything was entered at all.
If $SearchEngine, $TargetURL or $Keyword are still empty chains (or undefined) then we print an error message and exit the program (the operator for a logical OR is "||" or.. "or"! I don't get the differences yet).

In Notepad++ you can modify the execute command line (via the F6 shortcut) to:
perl "$(FULL_CURRENT_PATH)" -e www.google.com --target damienlearnsperl.blogspot.com --keyword learn perl

This result will appear as:

Notepad++ execution console
Note that the criteria entered by the user was "learn perl" and it was displayed as "learn" by the script. We'll just have to make sure that double quotes (") are used when the string input has a blank space.

French expression of the day:
"Ce que femme veut, Dieu le veut": A woman's will is God's will
As you can see, God and strong-minded women are universal.

Next posts:
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

RankSearch - Part II: parsing the Perl command line

RankSearch: The design
The design of our little script is laid out in the comment header from last post:

1. Get the parameters from the user
  • In a first version, ensure that all parameters are filled
  • Later, we can provide a default value for the search engine (Google)
  • Or even display all the results for a list of supported search engines
2. Launch an http request with the parameters given by the user
  • Spawn a process able to communicate back to our script
  • It will probably be in the form of "http:\\$engine-blabla-search_criteria-moreblabla"
  • Need to investigate different urls for different search engines
3. Parse and display the results transmitted by the http process
  • Search for the target URL
  • Keep track of rank count
  • Launch new http request with updated page number if target not found
  • Display result to user
Today, I'll strike off the first item of the list. Time to get interactive!
In order to ease the handling of user input, I discovered that Perl includes the Getopt::Long module by default. The link on CPAN will show you all possible uses of the module.
One must be careful not to omit the "\" character before the variable name (like I did at first).
We'll only use string (character chain) inputs:
use Getopt::Long;
GetOptions (" engine="s" => \$SearchEngine);
This will store in $SearchEngine the parameter entered from the following perl command line:
perl "$(FULL_CURRENT_PATH)" --engine www.google.com --target damienlearnsperl.blogspot.com --keyword "learn perl"
or
perl "$(FULL_CURRENT_PATH)" -engine www.google.com -target damienlearnsperl.blogspot.com -keyword "learn perl"
or even
perl "$(FULL_CURRENT_PATH)" -e www.google.com -t damienlearnsperl.blogspot.com -k "learn perl"
(provided you only have one entry in Getoptions starting with "e")

Here's the script:
#!/usr/bin/perl -w
# --------------------------------------------------
# File   : RankSearch.pl
# Author : DLP
# Date   : January 24th 2009
# Object : Looks in a search engine what is the rank
#          for a given website and a given keyword
# Input  : - Search engine URL, eg. "www.google.com"
#          - URL of website to monitor
#          - Search expression to investigate
# Bugs   : None
# To do  : - Launch http request
#          - Read html result
#          - Analyse result and display website rank
# --------------------------------------------------
use strict;
use Getopt::Long;   #Load module

# Global variable
my $PROG_NAME = "RankSearch";
my $VERSION   = "v0.0.1";
my $PROG_DATE = "January 24th 2009";

# --------------------------------------------------
# Main program
# --------------------------------------------------
# More global variables
my $SearchEngine = "";
my $TargetURL = "";
my $Keyword = "";

#Parse command line arguments
GetOptions ("engine=s"  => \$SearchEngine,  #string
    "target=s"  => \$TargetURL,
    "keyword=s" => \$Keyword);

# Check user input
if ($SearchEngine eq "" ||
$TargetURL eq "" || $Keyword eq "")
{
print "
You must enter a valid string for:
--engine  = search engine URL
--target  = the target of the search
--keyword = the search criteria
";
exit;
}

print "
$TargetURL is ranked nth on the $SearchEngine
search engine for the \"$Keyword\" criteria.";

__END__
Jan 24 2009 (0.0.1): first version of RankSearch
Jan 25 2009 (0.0.2): get params from command line

After getting the parameters, we check to see if anything was entered at all.
If $SearchEngine, $TargetURL or $Keyword are still empty chains (or undefined) then we print an error message and exit the program (the operator for a logical OR is "||" or.. "or"! I don't get the differences yet).

In Notepad++ you can modify the execute command line (via the F6 shortcut) to:
perl "$(FULL_CURRENT_PATH)" -e www.google.com --target damienlearnsperl.blogspot.com --keyword learn perl

This result will appear as:

Notepad++ execution console
Note that the criteria entered by the user was "learn perl" and it was displayed as "learn" by the script. We'll just have to make sure that double quotes (") are used when the string input has a blank space.

French expression of the day:
"Ce que femme veut, Dieu le veut": A woman's will is God's will
As you can see, God and strong-minded women are universal.

Next posts:
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • POD
  • Our first Perl program - Part VI: Add a GUI interface

Saturday, January 24, 2009

Retrieve the search rank for your blog automatically

I was reading the latest article over at Pretty Your Blog yesterday and it gave me an idea for a first script. The FileInfo program that I wanted to present is already written and I may come back to it later. The RankSearch project that I have in mind will be written from the ground up so you'll be able to monitor the progress as I crawl towards completion. I hope you'll pitch in as well!

RankSearch: The need
Kelly wrote in Pretty Your Blog:
I ran another (unofficial) experiment; I did a google search for frugal blog. And the result? Almost Frugal was on the 13th page of search results.
It is very likely that Kelly clicked on the next link at the bottom of each Google page until she found her blog's reference (by the way, if you are interested in improving your blog, you may want to visit Pretty Your Blog often :).
What if we could write a Perl script that automatically returns the Google rank based for any URL on a given keyword? That's the idea behind RankSearch.pl

RankSearch: The specifications
The script will have to be as generic as possible and would take 3 input parameters:
- Search engine URL (eg: "www.google.com" or "www.yahoo.com")
- URL of the blog you want to check the ranking for (eg: "almostfrugal.com")
- The search criteria you are investigating (eg: "frugal blog")

The output result will be a simple message of the type:
almostfrugal.com is ranked 7th on the google search engine for the "frugal blog" criteria.

It will run on Windows and Linux environments
Do you see anything else to add?

And here is the template for it:
#!/usr/bin/perl -w
# ----------------------------------------
# File : RankSearch.pl
# Author : DLP
# Date : January 24th 2009
# Object : Looks in a search engine what is the rank
# for a given website and a given keyword
# Input : - Search engine URL, eg. "www.google.com"
# - URL of website to monitor
# - Search expression to investigate
# Bugs : None
# To do : - Read input and store in script variable
# - Launch http request
# - Read html result
# - Analyse result and display website rank
# ----------------------------------------
use strict;

my $PROG_NAME = "RankSearch";
my $VERSION = "v0.0.1";
my $PROG_DATE = "January 24th 2009";

print "$PROG_NAME $VERSION from $PROG_DATE.\n";

__END__
Jan 24 2009: first version of RankSearch

French word of the day:
"économe": frugal

New posts:
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • Our first Perl program - Part VI: Add a GUI interface

Retrieve the search rank for your blog automatically

I was reading the latest article over at Pretty Your Blog yesterday and it gave me an idea for a first script. The FileInfo program that I wanted to present is already written and I may come back to it later. The RankSearch project that I have in mind will be written from the ground up so you'll be able to monitor the progress as I crawl towards completion. I hope you'll pitch in as well!

RankSearch: The need
Kelly wrote in Pretty Your Blog:
I ran another (unofficial) experiment; I did a google search for frugal blog. And the result? Almost Frugal was on the 13th page of search results.
It is very likely that Kelly clicked on the next link at the bottom of each Google page until she found her blog's reference (by the way, if you are interested in improving your blog, you may want to visit Pretty Your Blog often :).
What if we could write a Perl script that automatically returns the Google rank based for any URL on a given keyword? That's the idea behind RankSearch.pl

RankSearch: The specifications
The script will have to be as generic as possible and would take 3 input parameters:
- Search engine URL (eg: "www.google.com" or "www.yahoo.com")
- URL of the blog you want to check the ranking for (eg: "almostfrugal.com")
- The search criteria you are investigating (eg: "frugal blog")

The output result will be a simple message of the type:
almostfrugal.com is ranked 7th on the google search engine for the "frugal blog" criteria.

It will run on Windows and Linux environments
Do you see anything else to add?

And here is the template for it:
#!/usr/bin/perl -w
# ----------------------------------------
# File : RankSearch.pl
# Author : DLP
# Date : January 24th 2009
# Object : Looks in a search engine what is the rank
# for a given website and a given keyword
# Input : - Search engine URL, eg. "www.google.com"
# - URL of website to monitor
# - Search expression to investigate
# Bugs : None
# To do : - Read input and store in script variable
# - Launch http request
# - Read html result
# - Analyse result and display website rank
# ----------------------------------------
use strict;

my $PROG_NAME = "RankSearch";
my $VERSION = "v0.0.1";
my $PROG_DATE = "January 24th 2009";

print "$PROG_NAME $VERSION from $PROG_DATE.\n";

__END__
Jan 24 2009: first version of RankSearch

French word of the day:
"économe": frugal

New posts:
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Launch a HTTP request
  • How to install Google Analytics on your Blogger blog
  • Our first Perl program - Part IV: Read results from a HTML page
  • Perl help resources
  • Our first Perl program - Part V: Result analysis
  • Our first Perl program - Part VI: Add a GUI interface

Friday, January 23, 2009

Launch your Perl script from Notepad++

Today I am going to explain how you can be using Notepad++ to run Perl scripts.
It can be convenient to launch your program directly from the editor's environment to quickly check that it compiles.
Let's try and set up Notepad++ to launch the script from Wednesday's post.

In the Plugins menu, you will find the NppExec plugin.
Select Plugins>NppExec>Execute...
You can also use the convenient F6 shortcut.

Notepad++ interface to the execute command
Once the Execute... window is open, type in the following command:
perl "$(FULL_CURRENT_PATH)"$(FULL_CURRENT_PATH) is an internal Notepad++ variable that contains the full path of the file currently open in the editor.
There is a list of 10 such global variables here. We might come back to them later.
So, hitting F6 for our example is equivalent to typing the following line in a DOS shell:
perl C:\Perl\usr\skeleton2.pl

You can save this command line and give it a meaningful name ('perl' for example).
Of course, you can enter any command (or sequence of commands) that you would type at a DOS prompt:
perl -v
dir
...


The output result is visible on the Console window.Perl script execution on Notepad++ output console
You can get rid of the "Process..." lines by selecting Plugins>NppExec>No Internal Message
Also, if you want to repeat the previous command, you can just type Ctrl+F6.

If you know more Notepad++ tips, I'd love to hear from you!

A few words about the new skeleton:
The -w added at the end of the shebang line is the equivalent of use warnings;

$PROG_NAME, $VERSION and $PROG_DATE are called scalars. They are composed of a $ followed by a variable name. Scalars are used to represent a single element (in this case, they are all strings, because initialised as characters between double quotes).
The my function has to do with the scope of the variables. It is optional but I was told it is good practice to use in conjonction with the use strict command.
We'll see if we can figure out why later. If you have a clue, please drop a comment.

Finally, the last line makes use of the variables declared at the top of the script:
print "This is $PROG_NAME $VERSION from $PROG_DATE.\n";
Strings between double quotes (") are interpolated. This means that when the Perl interpreter sees $PROG_NAME between quotes, it will replace it by its current value.
If you replace the " by a single quote ('), then the output will become:
This is $PROG_NAME $VERSION from $PROG_DATE.\n

Come on, try it! All it takes are 2 key strokes and Ctrl+F6!
Finally, "\n" is understood as the next line character.

Today's French expression would not get approval from Larry Wall:
"La paresse est source de tous les vices": An idle person is the devil's cushion.
"Paresse" is the French word for lazyness. This is a quality for a developper according to Larry, because it pushes him/her to create scripts in order to automate his work and avoid repetitive tasks.

New posts:
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Add a GUI interface
  • How to install Google Analytics on your Blogger blog
  • First version of FileInfo script
  • Perl help resources

Launch your Perl script from Notepad++

Today I am going to explain how you can be using Notepad++ to run Perl scripts.
It can be convenient to launch your program directly from the editor's environment to quickly check that it compiles.
Let's try and set up Notepad++ to launch the script from Wednesday's post.

In the Plugins menu, you will find the NppExec plugin.
Select Plugins>NppExec>Execute...
You can also use the convenient F6 shortcut.

Notepad++ interface to the execute command
Once the Execute... window is open, type in the following command:
perl "$(FULL_CURRENT_PATH)"$(FULL_CURRENT_PATH) is an internal Notepad++ variable that contains the full path of the file currently open in the editor.
There is a list of 10 such global variables here. We might come back to them later.
So, hitting F6 for our example is equivalent to typing the following line in a DOS shell:
perl C:\Perl\usr\skeleton2.pl

You can save this command line and give it a meaningful name ('perl' for example).
Of course, you can enter any command (or sequence of commands) that you would type at a DOS prompt:
perl -v
dir
...


The output result is visible on the Console window.Perl script execution on Notepad++ output console
You can get rid of the "Process..." lines by selecting Plugins>NppExec>No Internal Message
Also, if you want to repeat the previous command, you can just type Ctrl+F6.

If you know more Notepad++ tips, I'd love to hear from you!

A few words about the new skeleton:
The -w added at the end of the shebang line is the equivalent of use warnings;

$PROG_NAME, $VERSION and $PROG_DATE are called scalars. They are composed of a $ followed by a variable name. Scalars are used to represent a single element (in this case, they are all strings, because initialised as characters between double quotes).
The my function has to do with the scope of the variables. It is optional but I was told it is good practice to use in conjonction with the use strict command.
We'll see if we can figure out why later. If you have a clue, please drop a comment.

Finally, the last line makes use of the variables declared at the top of the script:
print "This is $PROG_NAME $VERSION from $PROG_DATE.\n";
Strings between double quotes (") are interpolated. This means that when the Perl interpreter sees $PROG_NAME between quotes, it will replace it by its current value.
If you replace the " by a single quote ('), then the output will become:
This is $PROG_NAME $VERSION from $PROG_DATE.\n

Come on, try it! All it takes are 2 key strokes and Ctrl+F6!
Finally, "\n" is understood as the next line character.

Today's French expression would not get approval from Larry Wall:
"La paresse est source de tous les vices": An idle person is the devil's cushion.
"Paresse" is the French word for lazyness. This is a quality for a developper according to Larry, because it pushes him/her to create scripts in order to automate his work and avoid repetitive tasks.

New posts:
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Add a GUI interface
  • How to install Google Analytics on your Blogger blog
  • First version of FileInfo script
  • Perl help resources

Wednesday, January 21, 2009

Perl syntax highlighting in Blogger

I did it! It took me a while but I managed to get Perl syntax highlighting for this Blogger blog!
Check out the end result:
#!/usr/bin/perl -w
# ----------------------------------------
# File : Skeleton.pl
# Author : DLP
# Date : January 18th 2009
# Object : Template for new script
# Known bugs : None
# To do : Nothing
# ----------------------------------------
my $PROG_NAME = "Skeleton";
my $VERSION = "v0.0.2";
my $PROG_DATE = "January 21st 2009";

print "This is $PROG_NAME $VERSION from $PROG_DATE.\n";

__END__
Jan 18 2009: first version of the Perl skeleton
Jan 21 2009: v0.0.2
- changed "used warnings" into -w on shebang line
- created global variables for program version info
Pretty neat, don't you think?
I tried for a long time to modify the blog's layout (in the Blogger menu, Customize->Layout->Edit Html) by manually inserting lines of code as described here ot there.
Both of these sites are using syntaxighlighter for different languages. It looked really good and I wanted it! Unfortunately, syntaxhighlighter does not support Perl (why?!!).
After much trial and post botching, I was getting frustrated. I would see a good result from Windows Internet Explorer but not from Firefox (problem also noticed by Soon Hui, see his blog).
I finally stumbled on Fazibear's post. He shared a Blogger widget that whould do all the dirty work for you. All you have to do is to install the widget from the Layout page. Then, when you have code to add to your post, you edit the Html and surround your code by:


your code
Simple and effective... except that Perl syntax would not get highlighted (see list of supported languages here).
Thankfully, there are always helpful souls on the web and Bear Den Designs's blog has posted the bit of javascript code that was missing from the syntax highlighter widget.
I just had to edit the Blogger Syntax Highliter widget and copy the extra code between the lines:

dp.sh.Highlighter();dp.sh.Brushes.JScript.Aliases=['js','jscript','javascript'];

dp.sh.Brushes.Ruby=function()
...

Et voilà!

French word of the day:
"Victoire!": Victory!

Next posts:
  • Perl development tools - Part II: setting up Notepad++
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Add a GUI interface
  • How to install Google Analytics on your Blogger blog
  • First version of FileInfo script

Perl syntax highlighting in Blogger

I did it! It took me a while but I managed to get Perl syntax highlighting for this Blogger blog!
Check out the end result:
#!/usr/bin/perl -w
# ----------------------------------------
# File : Skeleton.pl
# Author : DLP
# Date : January 18th 2009
# Object : Template for new script
# Known bugs : None
# To do : Nothing
# ----------------------------------------
my $PROG_NAME = "Skeleton";
my $VERSION = "v0.0.2";
my $PROG_DATE = "January 21st 2009";

print "This is $PROG_NAME $VERSION from $PROG_DATE.\n";

__END__
Jan 18 2009: first version of the Perl skeleton
Jan 21 2009: v0.0.2
- changed "used warnings" into -w on shebang line
- created global variables for program version info
Pretty neat, don't you think?
I tried for a long time to modify the blog's layout (in the Blogger menu, Customize->Layout->Edit Html) by manually inserting lines of code as described here ot there.
Both of these sites are using syntaxighlighter for different languages. It looked really good and I wanted it! Unfortunately, syntaxhighlighter does not support Perl (why?!!).
After much trial and post botching, I was getting frustrated. I would see a good result from Windows Internet Explorer but not from Firefox (problem also noticed by Soon Hui, see his blog).
I finally stumbled on Fazibear's post. He shared a Blogger widget that whould do all the dirty work for you. All you have to do is to install the widget from the Layout page. Then, when you have code to add to your post, you edit the Html and surround your code by:


your code
Simple and effective... except that Perl syntax would not get highlighted (see list of supported languages here).
Thankfully, there are always helpful souls on the web and Bear Den Designs's blog has posted the bit of javascript code that was missing from the syntax highlighter widget.
I just had to edit the Blogger Syntax Highliter widget and copy the extra code between the lines:

dp.sh.Highlighter();dp.sh.Brushes.JScript.Aliases=['js','jscript','javascript'];

dp.sh.Brushes.Ruby=function()
...

Et voilà!

French word of the day:
"Victoire!": Victory!

Next posts:
  • Perl development tools - Part II: setting up Notepad++
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Add a GUI interface
  • How to install Google Analytics on your Blogger blog
  • First version of FileInfo script

Monday, January 19, 2009

Syntax highlighting woes

I am having some trouble with the setup of my posts.
I want the perl scripts that I publish to use the same syntax highlighting that you get in Notepad++.
So I used the NppExport plugin of Notepad++ and exported to a .html document (tried to a .rtf file also).
I copied and pasted the html code from the created html file to the WYSIWYG editor of blogger but the text formating has disappeared and I end up with something like that:

#!/usr/bin/perl
use warnings;
print "This is not so easy";

Then I tried to copy the html code from the exported html file into the "Edit Html" tab of the editing window but it doesnt work any better.

I have googled syntaxhighlighter but it doesn't support the Perl syntax. Somebody was nice enough to create a Perl extension. So I'll be trying it out in the next few hours. I will try re-publishing yesterday's post so don't go thinking that your feed reader has gone crazy.
And sorry for the inconvenience, I'm learning here ;)

French word of the day:
"J'apprends": I am learning

Syntax highlighting woes

I am having some trouble with the setup of my posts.
I want the perl scripts that I publish to use the same syntax highlighting that you get in Notepad++.
So I used the NppExport plugin of Notepad++ and exported to a .html document (tried to a .rtf file also).
I copied and pasted the html code from the created html file to the WYSIWYG editor of blogger but the text formating has disappeared and I end up with something like that:

#!/usr/bin/perl
use warnings;
print "This is not so easy";

Then I tried to copy the html code from the exported html file into the "Edit Html" tab of the editing window but it doesnt work any better.

I have googled syntaxhighlighter but it doesn't support the Perl syntax. Somebody was nice enough to create a Perl extension. So I'll be trying it out in the next few hours. I will try re-publishing yesterday's post so don't go thinking that your feed reader has gone crazy.
And sorry for the inconvenience, I'm learning here ;)

French word of the day:
"J'apprends": I am learning