Category Archives: Web development

All web based development (Server side programming, client side tool/languages, frameworks etc)

Message: Invalid argument: IE 8 Issue

In my Perl based server application, I want to execute a script in a new pop up window. I was using a syntax like:

var my_window = 
 window.open('open_window.pl, 'my window', 'width=800,height=600,resizable,scrollbars');

When I run the program in FF and Chrome it all works fine. I can open my pop-up window with above parameters and can see my desired result but the issue starts when I do the same test with IE 8. In spite of pop-up blocker off, the pop-up window was not launching, it was giving me a error message like:

Message: Invalid argument.
Line: 100 Char: 5
Code: 0

After debugging I found a solution which is some way very ridiculous. Issue was because of the reason that Microsoft does support the name property in window.open() with spaces [http://msdn.microsoft.com/en-us/library/ms536651%28v=vs.85%29.aspx] this means that if I make my window.open like [See GREEN string]

var my_window = 
 window.open('open_window.pl, 'my_window', 'width=800,height=600,resizable,scrollbars');

then it should works.

After doing this change it works with me for all the browsers.

I don’t know why IE always through such type of errors,  even if you launch the in-built Developer tool from IE interface then also you will get the same error message  ”Invalid arguments” no further clue/pointer to solve the issue. MS really has to improve the error handling messages to user.

So guys, be careful while developing pop-up window for all browsers specially for IE.

Thanks

Fork me on GitHub

Static variables/functions in Perl: Journey from C++ to Perl

I am relatively new to Perl.. in fact not so new now it’s been almost 3 years but frankly I am still learning new things on daily basis so much to learn. Great language and community it’s privilege to be part of ! Prior to Perl I was programming in C/C++ for 3 years and before that I was programming mostly in C and assembly languages. So it’s been wonderful journey till now learning many languages. Well, as C++ was my last language before Perl so I sometime use my C++ OO concepts to understand the same OO concepts in Perl. I don’t know if this is the correct approach or not but for me it helps. Last weekend I was just thinking about static variables and static functions/methods in C++.  Second obvious thought was how we implement them in Perl? or in fact do we really need them? As we don’t have private, public, protected keyword in Perl so how we are going to implement these features and setting the access inside and outside class? How Perl allocates the memory for static variable? Can we get this behavior just by declaring a variable outside of functions in a package or does const module will help?

So many questions, Well I might get some answers from web but I thought that it would be better idea to use this platform and ask directly to experts.  Would be nice if you guys can help me to understand and also direct me to some documentation links which compare the OO features in C++ and Perl.

Thanks for reading !

PDF creation in Perl

We in our project use HTMLDOC for PDF generation in Cent OS 5. We pass html files with some template info and run the HTMLDOC command line from perl program. This after multiple run gives me the correct PDF book with proper table of content, Index etc. The basic issue now I face with this engine is that it doesn’t support the new pdf features like PDF/A, CSS etc. and I don’t think HTMLDOC is very much in developmental mode. I want to introduce new engine to my application and tried some of the available options:

Prince:

This looks excellent and supports almost all modern PDF features. The input files can be xml, html etc and can be run as a batch process. But it has a licence fee.

PDF Reactor:

Looks fine also have the Perl wrapper for manipulating PDF but can’t run as a batch process for making single PDF from many HTML files. This can be done through Perl program by making a loop to documents which in result can produce combine PDF. Like prince it also has a licence fee.

WKHTMLTOPDF:

First thing I like about this engine is that this is a open source engine, beside being free it still supports CSS. It can be run as a batch process through Perl like HTMLDOC, prince. At first look it looks promising to me so I have decided to invest some time on it. The engine is QT and webkit based and in development phase.

I was wondering if I am missing something. Is there other engines someone has tried which go well with Perl?

Best regards,

Functional Programming in Perl: Part 2

* Closures

Lets take a look on closures:-

Need of closures:

Since closures are subroutine references with a bit of private data thrown in, they are very convenient to use as callback procedures in graphical user interfaces. There is a nice example which explains the need of using closures. This commonly used approach is called “smart” callback procedure.

For more info you can read chap 4 of Advanced Perl Programming by Sriram Srinivasan.

Functional Programming in Perl: Part 1

As we know  functional programming involves creating and manipulating functions to build up larger programs. This requires a language that allows functions to be used as input and return data to other functions. Perl has two important features that make it possible: –

* Code references

* Closures


Lets take code reference first:-


Need of code reference:

Sometimes we need to manipulate a subroutine by reference so we need to take the references to functions. This might happen if you need to create a signal handler, a Tk callback, or a hash of function pointers etc.


To get a code reference:

$cref = &func;

Reference to anonymous functions

$cref = sub { … };


To call a code reference:

Using a postfix arrow notation for dereferencing a code reference.

@returned = $cref->(@arguments);

A way to call the subroutine by reference prior to Perl 5.004

@returned = &$cref(@arguments);


Explanation:

If the name of a function is func, you can produce a reference to this code by preceding that name with & . You can also create anonymous functions using the sub {} notation. These code references can be stored just like any other reference. So we can say that code references are same as function pointers in C and C++ and which certainly helps to improve coding.


In my next post I will try to cover closures.


Thanks for reading.


Ref: Perl Cookbook by Tom Christiansen & Nathan Torkingston