<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding School</title>
	<atom:link href="http://coding-school.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://coding-school.com</link>
	<description>Staff Room!</description>
	<lastBuildDate>Mon, 11 Jul 2011 05:17:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>cubecart 5 navigation panel missing</title>
		<link>http://coding-school.com/cubecart-5-navigation-panel-missing/</link>
		<comments>http://coding-school.com/cubecart-5-navigation-panel-missing/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 05:17:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[middleware]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2189</guid>
		<description><![CDATA[If you login to your cubecartv5 panel and navigation if gone, then tack this onto your URL: _g=maintenance and click &#8220;clear cache&#8221; and submit. Worked for me. So your URL would look something like this: admin.php?_g=maintenance]]></description>
			<content:encoded><![CDATA[<p>If you login to your cubecartv5 panel and navigation if gone, then tack this onto your URL: _g=maintenance and click &#8220;clear cache&#8221; and submit. Worked for me. So your URL would look something like this: admin.php?_g=maintenance</p>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/cubecart-5-navigation-panel-missing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>web resilience and dns round robin</title>
		<link>http://coding-school.com/web-resilience-and-dns-round-robin/</link>
		<comments>http://coding-school.com/web-resilience-and-dns-round-robin/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 06:23:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[middleware]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2186</guid>
		<description><![CDATA[Nice piece of work on recent browsers resilience and dns round robin]]></description>
			<content:encoded><![CDATA[<p><a title="web resilience" href="http://blog.engelke.com/2011/06/07/web-resilience-with-round-robin-dns/" target="_blank">Nice piece of work on recent browsers resilience and dns round robin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/web-resilience-and-dns-round-robin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Signals</title>
		<link>http://coding-school.com/perl-signals/</link>
		<comments>http://coding-school.com/perl-signals/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 16:07:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-specialist]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2184</guid>
		<description><![CDATA[Perl Signals Perl allows you to trap signals using the %SIG associative array. Using the signals you want to trap as the key, you can assign a subroutine to that signal. The %SIG array will only contain those values which the programmer defines. Therefore, you do not have to assign all signals. For example, to [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl Signals</h3>
<p>Perl allows you to trap signals using the %SIG associative array. Using the signals you want to trap as the key, you can assign a subroutine to that signal. The %SIG array will only contain those values which the programmer defines. Therefore, you do not have to assign all signals. For example, to exit cleanly from a ^C: </p>
<p>
<pre class=indent>

$SIG{'INT'} = 'CLEANUP';

sub CLEANUP {

print "\n\nCaught Interrupt (^C), Aborting\n";

exit(1);

}
</pre>
<p>There are two special &#8220;routines&#8221; for signals called DEFAULT and IGNORE. DEFAULT erases the current assignment, restoring the default value of the signal. IGNORE causes the signal to be ignored. In general, you don&#8217;t need to remember these as you can emulate their functionality with standard programming features. DEFAULT can be emulated by deleting the signal from the array and IGNORE can be emulated by any undeclared subroutine. </p>
<p><Br></p>
<p>In 5.001, the $SIG{__WARN__} and $SIG{__DIE__} handlers may be used to intercept die() and warn(). For example, here&#8217;s how you could promote unitialized variables to trigger a fatal rather merely complaining: </p>
<p>
<pre class=indent>

#!/usr/bin/perl -w 

require 5.001;

$SIG{__WARN__} = sub {

if ($_[0] =~ /uninit/) 

{

   die $@;

} 

else 

{

   warn $@;

} 

};
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-signals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl DBI</title>
		<link>http://coding-school.com/perl-dbi/</link>
		<comments>http://coding-school.com/perl-dbi/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 15:58:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-specialist]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2182</guid>
		<description><![CDATA[Perl DBI Example The DBI module enables your Perl applications to access multiple database types transparently. You can connect to MySQL, MSSQL, Oracle, Informix, Sybase, ODBC etc. without having to know the different underlying interfaces of each. The API defined by DBI will work on all these database types and many more. What is DBI [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl DBI Example</h3>
<p>The DBI module enables your Perl applications to access</p>
<p>multiple database types transparently. You can connect to</p>
<p>MySQL, MSSQL, Oracle, Informix, Sybase, ODBC etc. without</p>
<p>having to know the different underlying interfaces of each.</p>
<p>The API defined by DBI will work on all these database types</p>
<p>and many more.</p>
<p><b>What is DBI and DBD::Oracle and where can one get it from?</b></p>
<p>DBI (previously called DBperl) is a database independent interface module for Perl. It defines a set of methods, variables and conventions that provide a consistent database interface independent of the actual database being used. </p>
<p>DBD::Oracle is the Oracle specific module for DBI. It can be downloaded from CPAN.</p>
<p><b>What DBI drivers have I got?</b></p>
<p>In DBI you can programmatically discover what DBI drivers are installed.</p>
<p></p>
<pre class=indent>

#!/usr/bin/perl -w

require DBI;

my @drivers = DBI->available_drivers;

print join(", ", @drivers), "n";
</pre>
<p><bR></p>
<p><b>Example:</b></p>
<pre class=indent>

use strict;

use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:orcl',

                        'username',

                        'password',

                        {

                          RaiseError => 1,

                          AutoCommit => 0

                        }

                      ) || die "Database connection not made: $DBI::errstr";

my $sql = qq{ CREATE TABLE employees ( id INTEGER NOT NULL,

                                       name VARCHAR2(128),

                                       position VARCHAR2(128),

                                     ) };

$dbh->do( $sql );

$dbh->disconnect();
</pre>
<p><b>SYBASE</b></p>
<p></p>
<p>Sybperl implements three Sybase extension modules to perl (version 5.002 or higher). Sybase::DBlib adds a subset of the Sybase DB-Library API. Sybase::CTlib adds a subset of the Sybase CT-Library (aka the Client Library) API. Sybase::Sybperl is a backwards compatibility module (implemented on top of Sybase::DBlib) to enable scripts written for sybperl 1.0xx to run with Perl 5. Using both the Sybase::Sybperl and Sybase::DBlib modules explicitly in a single script is not garanteed to work correctly. </p>
<p>The general usage format for both Sybase::DBlib and Sybase::CTlib is this: </p>
<p></p>
<pre class=indent>use Sybase::DBlib;

# Allocate a new connection, usually refered to as a database handle

$dbh = new Sybase::DBlib username, password;

# Set an attribute for this dbh:

$dbh->{UseDateTime} = TRUE;

# Call a method with this dbh:

$dbh->dbcmd(sql code);
</pre>
<p>The DBPROCESS or CS_CONNECTION that is opened with the call to new() is automatically closed when the $dbh goes out of scope: </p>
<pre class=indent>

sub run_a_query {

my $dbh = new Sybase::CTlib $user, $passwd;

my @dat = $dbh->ct_sql("select * from sysusers");

return @dat;

}

# The $dbh is automatically closed when we exit the subroutine.
</pre>
<p><b>Sybase::DBlib</b></p>
<p>A generic perl script using Sybase::DBlib would look like this: </p>
<pre class=indent>

use Sybase::DBlib;

$dbh = new Sybase::DBlib 'sa', $pwd, $server, 'test_app';

$dbh->dbcmd("select * from sysprocessesn");

$dbh->dbsqlexec;

$dbh->dbresults;

while(@data = $dbh->dbnextrow)

{

 .... do something with @data ....

}
</pre>
<p>$dbh = Sybase::DBlib->dbopen([$server [, $appname, [{attributes}] ]]) </p>
<p>Open an additional connection, using the current LOGINREC information. </p>
<p>$status = $dbh->dbuse($database) </p>
<p>Executes &#8220;use database $database&#8221; for the connection $dbh. </p>
<p>$status = $dbh->dbcmd($sql_cmd) </p>
<p>Appends the string $sql_cmd to the current command buffer of this connection. </p>
<p>$status = $dbh->dbsqlexec </p>
<p>Sends the content of the current command buffer to the dataserver for execution. See the DB-library documentation for a discussion of return values. </p>
<p>$status = $dbh->dbresults </p>
<p>Retrieves result information from the dataserver after having executed dbsqlexec(). </p>
<p>$status = $dbh->dbcancel </p>
<p>Cancels the current command batch. </p>
<p>$status = $dbh->dbcanquery </p>
<p>Cancels the current query within the currently executing command batch. </p>
<p>$dbh->dbfreebuf </p>
<p>Free the command buffer (required only in special cases &#8211; if you don&#8217;t know what this is you probably don&#8217;t need it <img src='http://coding-school.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>$dbh->dbclose </p>
<p>Force the closing of a connection. Note that connections are automatically closed when the $dbh goes out of scope. </p>
<p>$dbh->DBDEAD </p>
<p>Returns TRUE if the DBPROCESS has been marked DEAD by DBlibrary. </p>
<p>$status = $dbh->DBCURCMD </p>
<p>Returns the number of the currently executing command in the command batch. The first command is number 1. </p>
<p>$status = $dbh->DBMORECMDS </p>
<p>Returns TRUE if there are additional commands to be executed in the current command batch. </p>
<p>$status = $dbh->DBCMDROW </p>
<p>Returns SUCCEED if the current command can return rows. </p>
<p>$status = $dbh->DBROWS </p>
<p>Returns SUCCEED if the current command did return rows </p>
<p>$status = $dbh->DBCOUNT </p>
<p>Returns the number of rows that the current command affected. </p>
<p>$row_num = $dbh->DBCURROW </p>
<p>Returns the number (counting from 1) of the currently retrieved row in the current result set. </p>
<p>$status = $dbh->dbhasretstat </p>
<p>Did the last executed stored procedure return a status value? dbhasretstats must only be called after dbresults returns NO_MORE_RESULTS, ie after all the selet, insert, update operations of he sored procedure have been processed. </p>
<p>$status = $dbh->dbretstatus </p>
<p>Retrieve the return status of a stored procedure. As with dbhasretstat, call this function after all the result sets of the stored procedure have been processed. </p>
<p>$status = $dbh->dbnumcols </p>
<p>How many columns are in the current result set. </p>
<p>$status = $dbh->dbcoltype($colid) </p>
<p>What is the column type of column $colid in the current result set. </p>
<p>$status = $dbh->dbcollen($colid) </p>
<p>What is the length (in bytes) of column $colid in the current result set. </p>
<p>$string = $dbh->dbcolname($colid) </p>
<p>What is the name of column $colid in the current result set. </p>
<p>@dat = $dbh->dbretdata[$doAssoc]) </p>
<p>Retrieve the value of the parameters marked as &#8216;OUTPUT&#8217; in a stored procedure. If $doAssoc is non-0, then retrieve the data as an associative array with parameter name/value pairs. </p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-dbi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl OOP</title>
		<link>http://coding-school.com/perl-oop/</link>
		<comments>http://coding-school.com/perl-oop/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 15:56:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-specialist]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2180</guid>
		<description><![CDATA[Perl OOP Why Object Oriented approach? A major factor in the invention of Object-Oriented approach is to remove some of the flaws encountered with the procedural approach. In OOP, data is treated as a critical element and does not allow it to flow freely. It bounds data closely to the functions that operate on it [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl OOP</h3>
<p><b>Why Object Oriented approach?</b> </p>
<p>A major factor in the invention of Object-Oriented approach is to remove some of the flaws encountered with the procedural approach. In OOP, data is treated as a critical element and does not allow it to flow freely. It bounds data closely to the functions that operate on it and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. A major advantage of OOP is code re-usability.</p>
<p>Some important features of Object Oriented programming are as follows:</p>
<ul>
<li>Emphasis on data rather than procedure</p>
<li>Programs are divided into Objects
<li>Data is hidden and cannot be accessed by external functions
<li>Objects can communicate with each other through functions
<li>New data and functions can be easily added whenever necessary
<li>Follows bottom-up approach
</ul>
<p><b></p>
<p>Concepts of OOP: </b></p>
<li>Objects
<li>Classes
<li>Data Abstraction and Encapsulation
<li>Inheritance
<li>Polymorphism
<p>Briefly on Concepts:</b> </p>
<p><font class=question>Objects</font> </p>
<p>Objects are the basic run-time entities in an object-oriented system. Programming problem is analyzed in terms of objects and nature of communication between them. When a program is executed, objects interact with each other by sending messages. Different objects can also interact with each other without knowing the details of their data or code.</p>
<p><font class=question>Classes </font> </p>
<p>A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.</p>
<p><font class=question>Data Abstraction and Encapsulation </font> </p>
<p>Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes.</p>
<p>Storing data and functions in a single unit (class) is encapsulation. Data cannot be accessible to the outside world and only those functions which are stored in the class can access it.</p>
<p><font class=question>Inheritance </font></p>
<p>Inheritance is the process by which objects can acquire the properties of objects of other class. In OOP, inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.</p>
<p> <font class=question></p>
<p>Polymorphism </font><bR></p>
<p>Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation. Polymorphism is extensively used in implementing Inheritance.</p>
<p><b><i></p>
<p>Advantages of OOP</i></b> </p>
<p>Object-Oriented Programming has the following advantages over conventional approaches:</p>
<ul>
<li>OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
<li>OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
<li>OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
</ul>
<p><font class=question>Perl Package</font></p>
<li>To create a class in Perl, we first create a
<p>package. </p>
<li>A package (module) is a module of variables and
<p>subroutines, which can be re-used over and over again.</p>
<li>They provide a separate namespace within a Perl
<p>program that keeps subroutines and variables from </p>
<p>conflicting with those in other packages.</p>
<p><b></p>
<p>To declare a class named Person in Perl we do:</b></p>
<p>package Person;</p>
<li>The scope of the package definition extends to the
<p>end of the file </p>
<li>or until another package keyword is encountered.<br />
<h5>Perl Methods</h5>
<p>A method (subroutine) is a way of accessing objects. In </p>
<p>Perl, a method is just a subroutine defined within a </p>
<p>particular package. So to define a method to print our </p>
<p>Person object, we do:</p>
<p></p>
<pre class=indent>

sub print {

    my ($self) = @_; ## creating reference

    #print Person info

    printf( "Name:%s %snn", $self->firstName, $self->lastName );

}
</pre>
<p></p>
<p>The subroutine print is now associated with the package </p>
<p>Person. To call the method print on a Person object, we </p>
<p>use the Perl &#8220;arrow&#8221; notation. If the variable $mike </p>
<p>contains a Person object, we would call print on that </p>
<p>object by writing:</p>
<p></p>
<p>$mike->print();</p>
<p>When the object method is invoked, a reference to the </p>
<p>object is passed in along with any other arguments </p>
<p>(including class name). This is important since the </p>
<p>method now has access to the object on which it is to </p>
<p>operate.</p>
<h5>How do we create object?</h5>
<li>To create an instance of a class (an object) we need
<p>an object constructor. </p>
<li>This constructor is a method defined within the
<p>package. </p>
<li>Most programmers choose to name this object
<p>constructor method new, but in Perl one can use any </p>
<p>name.</p>
<li>One can use any kind of Perl variable as an object
<p>in Perl.
<li>Most Perl programmers choose either </p>
<p>references to arrays or hashes.</p>
<p></p>
<p>Let&#8217;s create our constructor for our Person class using </p>
<p>a Perl hash reference;</p>
<pre class=indent>

package Person;

sub new {

    my $self = {

        _firstName => undef,

        _lastName  => undef,

        _ssn       => undef,

        _address   => undef,

        _salary    => undef,

        _dept      => undef

    };

    bless $self, 'Person';

    return $self;

}

sub print {

    my ($self) = @_; ## creating reference

    #print Person info

    printf( "Name:%s %snn", $self->firstName, $self->lastName );

}
</pre>
<li>We created a subroutine (method) called new
<p>associatedwith the package Person. </p>
<li>Other method is print (as discussed earlier).
<li>The entries of the hash reference $self become the
<p>attributes of our object. We then use the bless function </p>
<p>on the hash reference. </p>
<li>The bless function takes two arguments: a reference
<p>to the variable to be marked and a string containing the </p>
<p>name of the class. This indicates that the variable now </p>
<p>belongs to the class Person.</p>
<p></p>
<p>To create an instance of our Person object:</p>
<p></p>
<p>my $mike = new Person();</p>
<p>We have not defined accessor methods or done any error </p>
<p>checking on the input values or keys or the anonymous </p>
<p>hash reference, but we have the start of a Perl Person </p>
<p>OO framework. To make our constructor more flexible and </p>
<p>to make our class inheritable (more on that later), we </p>
<p>can define it to use the $class variable to bless the </p>
<p>hash reference.</p>
<p></p>
<pre class=indent>

#constructor

sub new {

    my ($class) = @_;

    my $self = {

        _firstName => undef,

        _lastName  => undef,

        _ssn       => undef,

        _address   => undef,

        _salary    => undef,

        _dept      => undef

    };

    bless $self, $class;

    return $self;

}
</pre>
<p></p>
<p>Other object-oriented languages have the concept of </p>
<p>security of data to prevent a programmer from changing </p>
<p>an object data directly and so provide accessor methods </p>
<p>to modify object data. Perl does not have private </p>
<p>variables but we can still use the concept of accessor </p>
<p>methods and ask programmers to not mess with our object </p>
<p>innards.</p>
<p>For our Person class, we should provides accessor </p>
<p>methods for our object attributes; name, address, title, </p>
<p>ssn,salary,dept.</p>
<pre class=indent>

package Person;

use strict;

use Address;  #Person class will contain an Address

#constructor

sub new {

    my ($class) = @_;

    my $self = {

        _firstName => undef,

        _lastName  => undef,

        _ssn       => undef,

        _address   => undef

        _salary    => undef,

        _dept      => undef

    };

    bless $self, $class;

    return $self;

}

#accessor method for Person first name

sub firstName {

    my ( $self, $firstName ) = @_;

    $self->{_firstName} = $firstName if defined ($firstName);

    return $self->{_firstName};

}

#accessor method for Person last name

sub lastName {

    my ( $self, $lastName ) = @_;

    $self->{_lastName} = $lastName if defined($lastName);

    return $self->{_lastName};

}

#accessor method for Person address

sub address {

    my ( $self, $address ) = @_;

    $self->{_address} = $address if defined($address);

    return $self->{_address};

}

#accessor method for Person social security number

sub ssn {

    my ( $self, $ssn ) = @_;

    $self->{_ssn} = $ssn if defined($ssn);

    return $self->{_ssn};

}

sub salary {

    my ( $self, $salary ) = @_;

    $self->{_salary} = $salary if defined($salary);

    return $self->{_salary};

}

sub dept {

    my ( $self, $dept ) = @_;

    $self->{_dept} = $dept if defined($dept);

    return $self->{_dept};

}

sub print {

    my ($self) = @_;

    #print Person info

    printf( "Name:%s %snn", $self->firstName, $self->lastName );

}

1;
</pre>
<h5>Making Objects</h5>
<p>Object-oriented programming sometimes involves </p>
<p>inheritance. Inheritance simply means allowing one class </p>
<p>called the Child to inherit methods and attributes from </p>
<p>another, called the Parent, so you don&#8217;t have to write </p>
<p>the same code again and again. For example, we can have </p>
<p>a class Employee which inherits from Person. This is </p>
<p>referred to as an &#8220;isa&#8221; relationship because an employee </p>
<p>is a person. Perl has a special variable, @ISA, to help </p>
<p>with this. </p>
<p>@ISA governs (method) inheritance. So to create a new </p>
<p>Employee class that will inherit methods and attributes </p>
<p>from our Person class, we simply code:</p>
<p>
<pre class=indent>

# class Employee

package Employee;

use Person;

use strict;

our @ISA = qw(Person);    # inherits from Person
</pre>
<p>What we have done is load the Person class and declare </p>
<p>that Employee class inherits methods from it. We have </p>
<p>declared no methods for Employee but an Employee object </p>
<p>will behave just like a Person object. We should be able </p>
<p>to write code:</p>
<pre class=content>

#create Employee class instance

my $mike =  new Employee();

#set object attributes

$mike->firstName('mike');

$mike->lastName('Weis');
</pre>
<p>without any other changes.</p>
<p>Now let&#8217;s add some methods.</p>
<pre class=indent>

# class Employee

package Employee;

use Person;

use strict;

our @ISA = qw(Person);    # inherits from Person

#constructor

sub new {

    my ($class) = @_;

    #call the constructor of the parent class, Person.

    my $self = $class->SUPER::new();

    $self->{_id}   = undef;

    $self->{_title} = undef;

    bless $self, $class;

    return $self;

}

#accessor method for  id

sub id {

    my ( $self, $id ) = @_;

    $self->{_id} = $id if defined($id);

    return ( $self->{_id} );

}

#accessor method for  title

sub title {

    my ( $self, $title ) = @_;

    $self->{_title} = $title if defined($title);

    return ( $self->{_title} );

}

sub print {

    my ($self) = @_;

    # we will call the print method of the parent class

    $self->SUPER::print;

    $self->address->print;

}

1;
</pre>
<p>Looking at the code, you will notice that we have a new </p>
<p>method and a print method. Both the child class and its </p>
<p>parent class have the same method defined. We have </p>
<p>overridden the parent class&#8217; methods with the ones from </p>
<p>the child. When those methods are called on an Employee </p>
<p>object, we will get the Employee class&#8217; version of the </p>
<p>method. This concept of using the methods of an existing </p>
<p>object and modifying them is known as polymorphism.</p>
<p><b>Putting it together</b></p>
<p>So now that we have a complete set of classes, we can </p>
<p>write a small program to test them.</p>
<pre class=indent>

use strict;

use warnings;

use diagnostics;

use Employee;

#create Employee class instance

my $mike =  eval { new Employee(); }  or die ($@);

#set object attributes

$mike->firstName('mike');

$mike->lastName('Weis');

$mike->id(0731034);

$mike->title('Perl Programmer');

$mike->address( new Address() );

$mike->address->street('30 Hudson court');

$mike->address->city('Jersey City');

$mike->address->state('NJ');

$mike->address->zip('665030');

#diplay Employee info

$mike->print();
</pre>
<p>Let&#8217;s execute our code and see the output:</p>
<p>$ ./test.pl</p>
<p>Name:mike Weis</p>
<p>Address:30 Hudson court</p>
<p>Jersey City, NJ 665030</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl File Operations</title>
		<link>http://coding-school.com/perl-file-operations/</link>
		<comments>http://coding-school.com/perl-file-operations/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:49:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-training]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2177</guid>
		<description><![CDATA[Perl File operations Variables which represent files are called &#8220;file handles&#8221;, and they are handled differently from other variables. They do not begin with any special character &#8212; they are just plain words. By convention, file handle variables are written in all upper case, like FILE_OUT or SOCK. The file handles are all in a [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl File operations</h3>
<p>Variables which represent files are called &#8220;file handles&#8221;, and they are handled differently from other variables. They do not begin with any special character &#8212; they are just plain words. By convention, file handle variables are written in all upper case, like FILE_OUT or SOCK. The file handles are all in a global namespace, so you cannot allocate them locally like other variables. File handles can be passed from one routine to another like strings (detailed below). </p>
<p>The standard file handles STDIN, STDOUT, and STDERR are automatically opened before the program runs. Surrounding a file handle with <> is an expression that returns one line from the file including the &#8220;n&#8221; character, so returns one line from standard input. The <> operator returns undef when there is no more input. The &#8220;chop&#8221; operator removes the last character from a string, so it can be used just after an input operation to remove the trailing &#8220;n&#8221;. The &#8220;chomp&#8221; operator is similar, but only removes the character if it is the end-of-line character.</p>
<pre class=indent>

$line = ; ## read one line from the STDIN file handle 

chomp($line); ## remove the trailing "n" if present 
</pre>
<p></p>
<p><b>File Open and Close</b> </p>
<p>The &#8220;open&#8221; and &#8220;close&#8221; operators operate as in C to connect a file handle to a filename in the file system.</p>
<p></p>
<pre class=indent>

open(F1, "filename"); ## open "filename" for reading as file handle F1 

open(F2, ">filename"); ## open "filename" for writing as file handle F2 

open(F3, ">>appendtome") ## open "appendtome" for appending 

close(F1); ## close a file handle 
</pre>
<p></p>
<p>Open can also be used to establish a reading or writing connection to a separate process launched by the OS. This works best on Unix. </p>
<p></p>
<pre class=indent>

open(F4, "ls -l |"); ## open a pipe to read from an ls process 

open(F5, "| mail $addr"); ## open a pipe to write to a mail process 
</pre>
<p></p>
<p>Passing commands to the shell to launch an OS process in this way can be very convenient, but it&#8217;s also a famous source of security problems in CGI programs. When writing a CGI, do not pass a string from the client side as a filename in a call to open(). </p>
<p>Open returns undef on failure, so the following phrase is often to exit if a file can&#8217;t be opened. The die operator prints an error message and terminates the program. </p>
<p>
<pre class=indent>

open(FILE, $fname) || die "Could not open $fnamen"; 
</pre>
<p></p>
<p>In this example, the logical-or operator || essentially builds an if statement, since it only evaluates the second expression if the first if false. This construct is a little strange, but it is a common code pattern for Perl error handling. </p>
<p><b>Input Variants</b></p>
<p>In a scalar context the input operator reads one line at a time. In an array context, the input operator reads the entire file into memory as an array of its lines&#8230; @a = ; ## read the whole file in as an array of lines </p>
<p>This syntax can be dangerous. The following statement looks like it reads just a single line, but actually the left hand side is an array context, so it reads the whole file and then discards all but the first line&#8230;. </p>
<p>my($line) = ; </p>
<p>The behavior of also depends on the special global variable $/ which is the current the end-of-line marker (usually &#8220;n&#8221;). Setting $/ to undef causes to read the whole file into a single string. </p>
<p>
<pre class=indent>

$/ = undef; 

$all = ; ## read the whole file into one string 
</pre>
<p></p>
<p>You can remember that $/ is the end-of-line marker because &#8220;/&#8221; is used to designate separate lines of poetry. I thought this mnemonic was silly when I first saw it, but sure enough, I now remember that $/ is the end-of-line marker.</p>
<p><b>Print Output</b></p>
<p>Print takes a series of things to print separated by commas. By default, print writes to the STDOUT file handle. </p>
<p></p>
<pre class=indent>

print "Woo Hoon"; ## print a string to STDOUT 

$num = 42; 

$str = " Hoo"; 

print "Woo", $a, " bbb $num", "n"; ## print several things 
</pre>
<p></p>
<p>An optional first argument to print can specify the destination file handle. There is no comma after the file handle, but I always forget to omit it. </p>
<p>
<pre class=indent>

print FILE "Here", " there", " everywhere!", "n";  
</pre>
<p></p>
<p><b>File Processing Example</b></p>
<p>As an example, here&#8217;s some code that opens each of the files listed in the @ARGV array, and reads in and prints out their contents to standard output&#8230; </p>
<p></p>
<pre class=indent>

#!/usr/bin/perl -w 

require 5.004; 

## Open each command line file and print its contents to standard out 

foreach $fname (@ARGV) { 

open(FILE, $fname) || die("Could not open $fnamen"); 

while($line = ) { 

print $line; 

} 

close(FILE); 

} 
</pre>
<p></p>
<p>The above uses &#8220;die&#8221; to abort the program if one of the files cannot be opened. We could use a more flexible strategy where we print an error message for that file but continue to try to process the other files. Alternately we could use the function call exit(-1) to exit the program with an error code. Also, the following shift pattern is a common alternative way to iterate through an array&#8230; </p>
<pre class=indent>
<p>while($fname = shift(@ARGV)) {... </p>
<p>/pre></p></div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-file-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Regular Expressions</title>
		<link>http://coding-school.com/perl-regular-expressions/</link>
		<comments>http://coding-school.com/perl-regular-expressions/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:47:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-training]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2175</guid>
		<description><![CDATA[Perl Regular Expressions Metacharacters char meaning ^ beginning of string $ end of string . any character except newline * match 0 or more times + match 1 or more times ? match 0 or 1 times; or: shortest match &#124; alternative ( ) grouping; "storing" [ ] set of characters { } repetition modifier [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl Regular Expressions</h3>
<pre>

<b>Metacharacters

char meaning</b>

^      beginning of string 

$      end of string 

.      any character except newline 

*      match 0 or more times 

+      match 1 or more times 

?      match 0 or 1 times; or: shortest match 

|      alternative 

( )    grouping; "storing" 

[ ]    set of characters 

{ }    repetition modifier 

\      quote or special 
</pre>
<pre>

<b>Repetition</b>

a*     zero or more a's 

a+     one or more a's 

a?     zero or one a's (i.e., optional a) 

a{m}   exactly m a's 

a{m,}  at least m a's 

a{m,n} at least m but at most n a's repetition?

\t     tab 

\n     newline 

\r     return (CR) 

\xhh   character with hex. code hh 

\b     "word" boundary 

\B     not a "word" boundary 

\w     matches any single character classified as a 

       "word" character (alphanumeric or _) 

\W     matches any non-"word" character 

\s     matches any whitespace character (space, tab, newline) 

\S     matches any non-whitespace character  

\d     matches any digit character, equiv. to [0-9] 

\D     matches any non-digit character 

[characters] matches any of the characters in the sequence  

[x-y]        matches any of the characters from x to y 

             (inclusively) in the ASCII code  

[\-]         matches the hyphen character - 

[\n]         matches the newline; other single character 

             denotations with  apply normally, too  
</pre>
<p><font class=question>Examples</font></p>
<p><b>How do I extract everything between a the words &#8220;start&#8221; and &#8220;end&#8221;? </b></p>
<p>$mystring = &#8220;The start text always precedes the end of the end text.&#8221;;</p>
<p>if($mystring =~ m/start(.*)end/) {</p>
<p>	print $1;</p>
<p>}</p>
<p><b>How do I extract a complete number, like the year? </b></p>
<p>$mystring = &#8220;[2004/04/13] The date of this article.&#8221;;</p>
<p>if($mystring =~ m/(d+)/) {</p>
<p>print &#8220;The first number is $1.&#8221;;</p>
<p>}</p>
<p><b># find word that is bolded</b></p>
<p># returns: $1 = &#8216;text&#8217;</p>
<p>$line = &#8220;This is some <b>text</b> with HTML <tags> and &#8220;;</p>
<p>$line =~ m/<b>(.*)</b>/i;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Subroutine</title>
		<link>http://coding-school.com/perl-subroutine/</link>
		<comments>http://coding-school.com/perl-subroutine/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:44:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-training]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2173</guid>
		<description><![CDATA[Perl Subroutine sub mysubroutine { print "Not a very interesting routine\n"; print "This does the same thing every time\n"; } regardless of any parameters that we may want to pass to it. All of the following will work to call this subroutine. Notice that a subroutine is called with an &#038; character in front of [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl  Subroutine</h3>
<pre class=indent>

sub mysubroutine

{

	print "Not a very interesting routine\n";

	print "This does the same thing every time\n";

}
</pre>
<p></p>
<p>regardless of any parameters that we may want to pass to it. All of the following will work to call this subroutine. Notice that a subroutine is called with an &#038; character in front of the name: </p>
<pre class=indent>

&#038;mysubroutine;		# Call the subroutine

&#038;mysubroutine($_);	# Call it with a parameter

&#038;mysubroutine(1+2, $_);	# Call it with two parameters
</pre>
<h4>Parameters</h4>
<p>In the above case the parameters are acceptable but ignored. When the subroutine is called any parameters are passed as a list in the special @_ list array variable. This variable has absolutely nothing to do with the $_ scalar variable. The following subroutine merely prints out the list that it was called with. It is followed by a couple of examples of its use. </p>
<pre class=indent>

sub printargs

{

	print "@_n";

}

&#038;printargs("perly", "king");	# Example prints "perly king"

&#038;printargs("frog", "and", "toad"); # Prints "frog and toad"
</pre>
<p></p>
<p>Just like any other list array the individual elements of @_ can be accessed with the square bracket notation: </p>
<pre class=indent>

sub printfirsttwo

{

	print "Your first argument was $_[0]n";

	print "and $_[1] was your secondn";

}
</pre>
<p></p>
<p>Again it should be stressed that the indexed scalars $_[0] and $_[1] and so on have nothing to with the scalar $_ which can also be used without fear of a clash. </p>
<p><font class=question>Returning values</font></p>
<p>Result of a subroutine is always the last thing evaluated. This subroutine returns the maximum of two input parameters. An example of its use follows. </p>
<pre class=indent>

sub maximum

{

	if ($_[0] > $_[1])

	{

		$_[0];

	}

	else

	{

		$_[1];

	}

}

$biggest = &#038;maximum(37, 24);	# Now $biggest is 37
</pre>
<p></p>
<p>The &#038;printfirsttwo subroutine above also returns a value, in this case 1. This is because the last thing that subroutine did was a print statement and the result of a successful print statement is always 1. </p>
<h4>Local variables</h4>
<p>The @_ variable is local to the current subroutine, and so of course are $_[0], $_[1], $_[2], and so on. Other variables can be made local too, and this is useful if we want to start altering the input parameters. The following subroutine tests to see if one string is inside another, spaces not withstanding. An example follows. </p>
<pre class=indent>

sub inside

{

	local($a, $b);                  # Make local variables

	($a, $b) = ($_[0], $_[1]);      # Assign values

	$a =~ s/ //g;                   # Strip spaces from

	$b =~ s/ //g;                   # local variables

	($a =~ /$b/ || $b =~ /$a/);     # Is $b inside $a

					# or $a inside $b?

}

&#038;inside("lemon", "dole money");		# true
</pre>
<p></p>
<p>In fact, it can even be tidied up by replacing the first two lines with </p>
<p>local($a, $b) = ($_[0], $_[1]);</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-subroutine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl References</title>
		<link>http://coding-school.com/perl-references/</link>
		<comments>http://coding-school.com/perl-references/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:41:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-training]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2171</guid>
		<description><![CDATA[Perl References I&#8217;m happiest writing Perl code that does not use references because they always give me a mild headache. Here&#8217;s the short version of how they work. The backslash operator () computes a reference to something. The reference is a scalar that points to the original thing. The &#8216;$&#8217; dereferences to access the original [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>Perl References</h3>
<p>I&#8217;m happiest writing Perl code that does not use references because they always give me a mild headache. Here&#8217;s the short version of how they work. The backslash operator () computes a reference to something. The reference is a scalar that points to the original thing. The &#8216;$&#8217; dereferences to access the original thing. Suppose there is a string&#8230; </p>
<p>$str = &#8220;hello&#8221;; ## original string</p>
<p>And there is a reference that points to that string&#8230; </p>
<p>$ref = $str; ## compute $ref that points to $str </p>
<p>The expression to access $str is $$ref. Essentially, the alphabetic part of the variable, &#8216;str&#8217;, is replaced with the dereference expression &#8216;$ref&#8217;&#8230; </p>
<p>print &#8220;$$refn&#8221;; ## prints &#8220;hello&#8221; &#8212; identical to &#8220;$strn&#8221;; </p>
<p>Here&#8217;s an example of the same principle with a reference to an array&#8230; </p>
<p>@a = (1, 2, 3); ## original array </p>
<p>$aRef = @a; ## reference to the array </p>
<p>print &#8220;a: @an&#8221;; ## prints &#8220;a: 1 2 3&#8243; </p>
<p></p>
<p>print &#8220;a: @$aRefn&#8221;; ## exactly the same </p>
<p>Curly braces { } can be added in code and in strings to help clarify the stack of @, $, &#8230; </p>
<p>print &#8220;a: @{$aRef}n&#8221;; ## use { } for clarity </p>
<p>Here&#8217;s how you put references to arrays in another array to make it look two dimensional&#8230; </p>
<p>@a = (1, 2, 3); @b = (4, 5, 6); </p>
<p>@root = (@a, @b); </p>
<p>print &#8220;a: @an&#8221;; ## a: (1 2 3) </p>
<p>print &#8220;a: @{$root[0]}n&#8221;; ## a: (1 2 3)</p>
<p>print &#8220;b: @{$root[1]}n&#8221;; ## b: (4 5 6) </p>
<p></p>
<p>scalar(@root) ## root len == 2 </p>
<p>scalar(@{$root[0]}) ## a len: == 3 </p>
<p></p>
<p>For arrays of arrays, the [ ] operations can stack together so the syntax is more C like&#8230; </p>
<p>$root[1][0] ## this is 4
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl if else</title>
		<link>http://coding-school.com/perl-if-else/</link>
		<comments>http://coding-school.com/perl-if-else/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 16:39:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[perl-coding-training]]></category>

		<guid isPermaLink="false">http://coding-school.com/?p=2169</guid>
		<description><![CDATA[The if&#8230;else Statement This statement uses a relational expression to check the validity of a condition and execute a set of statements enclosed in braces. It returns a Boolean value, true or false, according to the validity of the condition. The syntax of the if&#8230;else statement is: if(condition) { block of statement(s); } else { [...]]]></description>
			<content:encoded><![CDATA[<div class="content">
<h3>The if&#8230;else Statement</h3>
<p>This statement uses a relational expression to check the validity of a condition and execute a set of statements enclosed in braces. It returns a Boolean value, true or false, according to the validity of the condition. The syntax of the if&#8230;else statement is:</p>
<p></p>
<pre class=indent>

if(condition)

{

	block of statement(s);

}

else

{

	block of statement(s);

}
</pre>
<p>In this syntax, condition is a relational expression. If the result of this expression is true, then the block of statements following the if statement is executed. Otherwise, the block of statements following the else statement is executed.</p>
<p><i>In Perl, unlike other languages, all loops and conditional constructs require statements to be enclosed in braces, even for single statements.</i></p>
<p></p>
<pre class=indent>

#! /usr/bin/perl

print "Enter a value for a: ";

$a = <>;

print "Enter a value for b: ";

$b  = <>;

if ($a>$b)

{

   print "a is greater than b\n";

}

else

{

   print "b is greater than a\n";

}
</pre>
<p></p>
<p>In this example, the if clause checks whether $a is greater than $b. If the value of $a is greater than $b, then the result is: a is greater than b. Otherwise, the control transfers to the code following the else clause and the statement associated with the else clause is printed as a result. </p>
<p><font class=question>The if&#8230;elsif&#8230;else Statement</font></p>
<p>This statement is used when there is more than one condition to be checked. The syntax of the if&#8230;elsif&#8230;else statement is:</p>
<p></p>
<pre class=indent>

if (condition)

{

	block of statement(s);

}

elsif (condition)

{

	block of statement(s);

}

else

{

	block of statement(s);

}
</pre>
<p></p>
<p>In this syntax, if the condition associated with the if clause is false, the control transfers to elsif clause that checks for the next condition. The code associated with elsif clause is executed only if the condition is true or the code associated with the else clause is executed.</p>
<pre class=indent>

#! /usr/bin/perl

print "Enter the score of a student: ";

$score = <>;

if($score>=90)

{

  print "Excellent Performance\n";

}

elsif($score>=70 &#038;&#038; $score<90)

{

  print "Good Performance\n";

}

else

{

  print "Try hard\n";

}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://coding-school.com/perl-if-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

