Slick wrote:
What do you guys do to practice? Do you practice one script over and over again? Do you read differnt scripts and figure out what is happening in each one? Do you think of ideas to do things, then make the script for that?

As they say:

    "Necessity is the mother of invention."

I write Perl scripts because I need to get something done with my computers.


Monotonous, repetitive tasks are good candidates. For example, copying file trees to a backup drive, making a tar / gzip archive of some files with a date/ time stamp in the archive name, and shutting down a network of computers in the proper order. In fact, I've written and re-written those scripts dozens of times (as my needs change/ expectations increase and as I learn more about Perl). I then write one script to rule them all, so at the end of the day I can launch one script, turn off the monitor, and go to bed. :-)


The steps are:

1. Get an idea -- e.g. "Hey, I bet I could write a Perl script to do this..." (need).

2. Research in exact detail what it takes to make "this" happen -- e.g. data, algorithms, sequence of steps, command syntax, reference information, etc. (analysis).

3.  Figure out how to accomplish "this" in Perl (design and implementation):

a. One approach is to break down the overall process into smaller steps and solve them one at a time (procedural or structured programming). This is the traditional approach, and how I learned to program.

b. Another approach is to model the system as objects that contain both data and the operations that act upon that data (object-oriented programming). This is a newer approach, and makes it easier to solve larger and more complex problems.


I prefer books for learning and for reference, and found "Learning Perl", "Programming Perl", and especially "The Perl Cookbook" to be invaluable when it came time to start writing Perl code. I still refer to the later two often. When you're ready for libraries (modules), object-oriented Perl, automated testing, etc., get "Intermediate Perl".


Another aspect to #3 is learning to leverage all the "free" Perl scripts and modules that are available on the Comprehensive Perl Archive Network:

        http://www.cpan.org/

Data::Dumper is one such module. It is included in the base Perl distribution, so you don't have to worry about downloading/ installing it. I find it invaluable for debugging (the old-fashioned way, with "print" statements):

        2009-10-06 20:56:25 dpchr...@p43400e ~
        $ cat foo
        #! /usr/bin/perl -w
        use strict;
        use warnings;
        use Data::Dumper;

        my $debug = 1;

        print join(" ", __FILE__, __LINE__,
                   Data::Dumper->Dump([...@argv], [qw(*ARGV)])
        ) if $debug;

        2009-10-06 20:56:29 dpchr...@p43400e ~
        $ ./foo -x -y 'hello, world!' 123
        ./foo 8 @ARGV = (
                  '-x',
                  '-y',
                  'hello, world!',
                  '123'
                );


HTH,

David


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to