Perl course - PowerPoint PPT Presentation

1 / 64
About This Presentation
Title:

Perl course

Description:

Return a string with just the first letter in lower case. my $lfstring = lcfirst($string) ... The green and/or red line can contain part of the data. ... – PowerPoint PPT presentation

Number of Views:111
Avg rating:3.0/5.0
Slides: 65
Provided by: joha96
Category:
Tags: course | perl

less

Transcript and Presenter's Notes

Title: Perl course


1
Perl course
The teacher Peter Wad Sackett Center for
Biological Sequence Analysis pws_at_cbs.dtu.dk Compu
ter scientist. Programmed in Perl since
1995. Taught Perl since 2002.
2
Books
The beginner book Learning Perl, 4th ed. by
Randal Schwartz Tom Christiansen (O'Reilly)
The bible Programming Perl, 3rd ed. by Larry
Wall, Tom Christiansen Jon Orwant (O'Reilly)
The rest are more or less successful spin-offs.
3
Links
Main Perl web site http//www.perl.org/ Perl
documentation http//perldoc.perl.org/ Perl
module/library repository http//cpan.perl.org/ On
line perl book http//www.perl.org/books/beginning
-perl/
4
Perl strengths and weaknesses
PROS Fairly standard C-like syntax Runs on Unix,
Windows and Mac among others Powerful text
parsing facilities Large library base Quick
development Known as the glue that connects
applications CONS Not as quick as compiled
languages Possible (and easy) to make ugly and
hard to maintain code
5
Variables
All variables (scalars) starts with . A variable
name may contain alphanumeric characters and
underscore. Case matters. A simple variable can
be either a string or floating point number, but
does not need to be declared as any specific
type. Perl has a number of predefined variables
(sometimes used), consisting of and a single
non-alphanumeric character. Examples var1, i,
MyCount, remember_this.
6
Numbers and operators
Numbers are assigned in a natural manner num
1 num 324.657 num -0.043 Standard
numeric operators - / Bitwise
operators (or) (and) (xor) (not)
gtgt (rightshift) ltlt (leftshift) Autoincrement
and autodecrement --
7
Strings
Strings are assigned with quotes string This
is a literal string string This is an
interpolated string\n Interpolated strings are
searched for variables and special character
combinations that has meaning, like \n for
newline and \t for tab. If a number is used in a
string context then it is changed to a string and
vice versa. String operators . (concatenation)
x (repetition)
8
Conditional statement
A standard if statement if (predicate)
this will be executed if the predicate is
true if statements exists in various forms in
perl if (predicate) this will be executed
if the predicate is true elsif (predicate2)
no spelling mistake this will be executed
if this predicate is true else finally
this is excuted if no predicates where true Can
be turned around unless (predicate) this
will be executed if the predicate is false
9
Predicates
Predicates are simple boolean expressions that
can be stringed together via boolean operators
forming complex logic. Numerical comparison
operators lt gt lt gt !
ltgt String comparison operators lt gt le
ge eq ne cmp Boolean operators and
or ! not xor Examples age gt 18 and
height lt 1.4 (name eq Peter or name eq
Chris) and wage lt 25000 Perl is using
short-circuit (lazy) evaluation.
10
Loops - while
The standard while loop. some
initialization while (predicate) code
which is executed while the predicate is
true There are various forms of the while
loop until (predicate) code which is
executed while the predicate is false do
code while (predicate)
11
Loops - for
Perl has the standard for loop for(init
predicate increment) for(i 0 i lt 10
i) code executed 10 times A infinite
loop is often written as for () code
executed forever
12
Loops - control
There are 3 loop control primitives that can be
used in all forms of loops last breaks (ends)
the loop next starts the loop from the top and
executes the predicate redo starts the loop
from the top, do not execute the predicate
13
Shorthand notation
Often if statements and sometimes loops only has
one line of code to be executed in the block.
Perl has a shorthand notation for that. if (age
gt 80) print Old\n Shorthand print
Old\n if age gt 80 x 0 unless x gt 0 print
i\n for (i 1 i lt 10, ) As seen the
structure of the statement is turned around.
14
Output printing to screen
The print statement prints a comma separated list
of values. print Hello world\n print Result
is , num1 num2, \n print My name is
name\n For better output formatting use
printf, which is similar to the C
function. printf (02d/02d 04d\n, day,
month, year) printf (Sum is 7.2f\n,
sum) The output of print(f) goes to the last
selected filehandle unless otherwise specified.
This is usually STDOUT, which is usually the
screen.
15
Input getting it from the keyboard
The keyboard is usually STDIN unless redirection
is in play. Lines are read from the keyboard like
any lines are read from a filehandle. line
ltSTDINgt Perl is mostly used in applications
where linebased I/O makes sense, even though Perl
can do other types of I/O. When reading a line,
it is important to realize that a line ends with
a newline, which is part of what is read. You
have to get rid of that newline so often that
Perl has a function for that chomp line If
there is no input on the line (EoF, EoT) then
line is assigned the undefined value. There is a
function for checking that, too. if (defined
line)
16
A simple Perl program
!/usr/bin/perl w print Hello user !\nWhat is
your name name ltSTDINgt chomp name if
(name eq Peter) print Ahh, welcome back,
sensei\n else print Good of you to
come, name\n
17
Strict Perl
Perl is a rather loose and forgiving language.
This can be improved somewhat by using
strict. !/usr/bin/perl w use strict This will
enforce variable declaration and proper scoping,
disallow symbolic references and most barewords.
This is a good thing as some stupid errors are
caught and the code is more portable and version
independant. Variables are declared by the key
word my and are private (local) to the block in
which they are declared.
18
Scope (lexical)
A block can be considered as the statements
between and . A variable declared with my is
known only in the enclosing block. Only the most
recent declared variable is known in the
block. my age declaring age in main
program making it a global here is unwritten
code that gets age if (age lt 10) for (my i
1 i lt age i) private i
print Year i\n elsif (age gt 80)
my age 40 private age only known in this
block print You are only age years
old.\n print You are really age years
old.\n
19
Opening files
The modern open is a three parameters function
call. open(FILEHANDLE, mode, filename) The
usual file modes are lt reading gt writing gtgt ap
pending lt reading and writing - output is
piped to program in filename - output from
program in filename is piped (read) to
Perl open(IN, lt, myfile.txt) or die Cant
read file !\n close IN
20
Semi-useful program
!/usr/bin/perl w Summing numbers in a
file use strict print What file should I sum
my filename ltSTDINgt chomp
filename open(IN, lt, filename) or die
Error !\n my sum 0 standard way of
reading a file line by line in Perl while
(defined (my line ltINgt)) chomp line
sum line print The sum is sum\n
21
File system functions
exit optional_error_code die This sentence is
printed on STDERR unlink filename rename
old_filename, new_filename chmod 0755,
filename mkdir directoryname, 0755 rmdir
directoryname chdir directoryname opendir(DIR,
directoryname) readdir(DIR) closedir
DIR system(program parameters) my output
program parameters
22
File test operators
There is a whole range of file test operators
that all look like X. print File exists if e
filename Some of the more useful are -e True
if file exists -z True if file has zero
size -s Returns file size -T True if text
file -B True if binary file -r True if file is
readable by effective uid/gid -d True if file is
a directory -l True if file is a symbolic link
23
String functions 1
Remove a trailing record separator from a string,
usually newline my no_of_chars_removed chomp
line Remove the last character from a
string my char_removed chop line Return
lower-case version of a string my lstring
lc(string) Return a string with just the first
letter in lower case my lfstring
lcfirst(string) Return upper-case version of a
string my ustring uc(string) Return a
string with just the first letter in upper
case my ufstring ucfirst(string) Get
character this number represents my char
chr(number) Find a character's numeric
representation my number ord(char)
24
String functions 2
Strings start with position 0 Return the number
of charaters in a string my len
length(string) Find a substring within a
string my pos index(string, substring,
optional_position) Right-to-left substring
search my pos rindex(string, substring,
optional_position) Flip/reverse a string my
rstring reverse string Formatted print into
a string (like printf) sprintf(format,
variables) Get or alter a portion of a
string my substring substr(string,
position) my substring substr(string,
position, length) substr(string, position,
length, replacementstring)
25
Stateful parsing
Stateful parsing is a robust and simple method to
read data that are split up on several lines in a
file. It works by recognizing the line (or line
before) where data starts (green line) and the
line (or line after) it ends (red line). The
green and/or red line can contain part of the
data. The principle is shown here, but code can
be easily added to handle specific situations. my
flag 0 my data while (defined (my
line ltINgt)) flag 0 if line eq red
data . line if flag 1 flag 1 if
line eq green
26
Arrays
Arrays are denoted with _at_. They are initalized as
a comma separeted list of values (scalars). They
can contain any mix of numbers, strings or
references. The first element is at position 0,
i.e. arrays are zero-based. There is no need to
declare the size of the array except for
performance reasons for large arrays. It grows
and shrinks as needed. my _at_array my _at_array (1,
two, 3, four is 4) Individual elements are
accessed as variables, i.e. with print
array0, array1 Length of an
array. scalar(_at_array) array 1
27
Array slices
You can access a slice of an array. my _at_slice
_at_array5..8 my _at_slice _at_arrayposition..arra
y my (var1, var2) _at_array4, pos Or
assign to a slice. _at_array4..7 (1, 2, 3,
4) _at_arraypos, 5 _at_tmp2..3 Printing
arrays print _at_array, _at_array
28
Iterating over arrays
A straightforward for-loop. for (my i 0 i lt
array i) print arrayi2,
\n The special foreach-loop designed for
arrays. foreach my element (_at_array) print
element2, \n If you change the element
inside the foreach loop the actual value in the
array is changed.
29
Array functions 1
Inserting an element in the beginning of an
array unshift(_at_array, value) Removing an
element from the beginning of an array my value
shift(_at_array) Adding an element to the end of
an array push(_at_array, value) Removing an
element from the end of an array my value
pop(_at_array) Adding and/or removing element at
any place in an array my _at_goners splice(_at_array,
position) my _at_goners splice(_at_array,
position, length) my _at_goners splice(_at_array,
position, length, value) my _at_goners
splice(_at_array, position, length, _at_tmp)
30
Array functions 2
Sorting an array. _at_array sort _at_array
alphabetical sort _at_array sort a ltgt b
_at_array numerical sort Reversing an
array. _at_array reverse _at_array Splitting a
string into an array. my _at_array split(m/regex/,
string, optional_number) my _at_array split(
, string) Joining an array into a string my
string join(\n, _at_array) Find elements in a
list test true against a given criterion
_at_newarray grep(m/regex/, _at_array)
31
Predefined arrays
Perl has a few predefined arrays. _at_INC, which is
a list of include directories used for location
modules. _at_ARGV, which is the argument vector. Any
parameters given to the program on command line
ends up here. ./perl_program 1 file.txt _at_ARGV
contains (1, file.txt) at program start. Very
useful for serious programs.
32
Regular expressions classes
Regular expressions return a true/false value and
the match is available. print match if string
m/regex/ print match if not string !
m/regex/ Character classes with
m/ABCDA/ m/Aa-gA/ m/A12a-zA/ m/Aa-z\dA/
Standard classes \s whitespace, i.e. \t\n\r\f
\S non-whitespace \w word char, i.e.
A-Za-z0-9_ \W non-word \d digit, i.e.
0-9 \D non-digit . any character except
newline \n newline \char escape for special
characters like \\, \ etc.
33
Regular expressions quantifiers
Often a match contains repeated parts, like an
unknown number of digits. This is done with a
quantifier that follows the character. ? 0 or 1
occurence 1 or more occurences 0 or more
occurences n excatly n occurences n, at least
n occurences n,m between n and m
occurences m/AB?/ m/A-Z1,2\d4,/ Matches
are greedy, i.e. will match as much as possible.
This can be changed by adding ? to the quantifier
making the match non-greedy. m/A?/
34
Regular expressions groups
Often a pattern consists of repeated groups of
characters. A group is created by parenthesis.
This is also the way to extract data from a
match. m/(AB)/ m/(A-Z1,2\d4,)/ The match
of the first group will be available in 1,
second group in 2... If a data line looks like
e.g. first line in a swissprot entry ID
ASM_HUMAN STANDARD PRT 629 AA.
id 1 if line m/ID\s(\w)/ Alternation
with is a way to match either this or
that. name 1 if string m/(PeterChris)/
35
Regular expressions bindings
A very useful and performance efficient trick is
to bind the match to the beginning and/or end of
the line. m/ID\s(\w)/ caret at first position
binds to the beginning of the line m/pattern/ dol
lersign at last position binds to the end of the
line Always define patterns to be as narrow as
possible as that makes them stronger and more
exact. Regular expressions are best created by
matching the pattern you look for, not by
matching what the pattern is not. Variables can
be used in a pattern.
36
Regular expressions modifiers
The function of a RE can be modified by adding a
letter after the final /. The most useful
modifiers are i case-insensitive g global all
occurences o compile once, improve performance
when not using variables m multiline - and
match internal lines m/peter/io finds Peter and
PETER in a line - fast. A wonderful trick to find
all numbers in a line is my _at_array line
m/\d/g my _at_array line m/(\d)/go print
Good number if line m/-?\d(\.\d)?/o
37
Regular expressions - substitution
Regular expressions can also be used to replace
text in a string. This is substitution and is
quite similar to matching. The newtext is quite
literal, however 1, 2 etc works here. string
s/regex/newtext/ string s/(\d) kr/1
dollar/ replacing kroner with dollar There is
a useful extra modifier e which allows perl code
to be executed as the replacement text in
substitution. string s/(\d) kr/X x
length(1) . dollar/e replacing kroner with
dollar, but replacing the amount with xes.
38
Transliteration
Somewhat like simple substitition,
transliteration (or translation) replaces
characters with other chararcters in a
string. string tr/SEARCHLIST/REPLACEMENTLIST/
dna tr/ATCGatcg/TAGCTAGC/ Complementing
dna letters tr/A-Z/a-z/ lowercasing a
string The modifiers are c Complement the
SEARCHLIST. d Delete found but unreplaced
characters. s Squash (remove) duplicate replaced
characters. Transliteration returns the number
of characters replaced, so a quick way to count
the number of, say As in a string is count
string tr/A/A/
39
Hashes
Hashes are unordered lists and are very fexible
data structures. Arrays can be considered as a
special case of hashes. is used for a hash.
Data is a hash is a number of key/value pairs.
One of the more obvious uses af a hash is as a
translation table. my hash (1 gt one, one
gt 1, 2 gt two, two gt 2) print hash1,
\n if hashtwo number hash3
three It should be obvious from the key/value
pair structure, that a key is unique in the hash,
where a value can be repeated any number of
times. Hash slices are possible on the values.
Notice the _at_. my _at_slice _at_hashone, two
40
Hash functions
delete hashkey Deletes a key/value
pair exists hashkey Returns true if the
key/value pair exists keys hash Returns an
array with all the keys of the hash values
hash Returns an array with the values of the
hash each hash Used in iteration over the
hash The usual ways to iterate over a hash
are foreach my key (keys hash) print key
gt hashkey\n while (my (key, value)
each hash) print key gt value\n
41
Semi-advanced hash usage
Sparse N-dimensional matrix You need a large
sparsely populated N-dimensional matrix. A very
good and easy way is to use a hash, even if a
hash is a "flat" data structure. The secret is in
constructing an appropriate key. An example could
be a three dimensional matrix which could be
populated in this way matrix"x,y,z"
value Access the matrix like this value
exists matrix"x,y,z" ? matrix"x,y,z"
0 Notice that x, y, z is not limited to
numbers, they could be SwissProt IDs or other
data that makes sense. The matrix does not have
to be regular.
42
Subroutines 1
Subroutines serve two functions Code reusage and
hiding program complexity. All parameters to a
subroutine are passed in a single list _at__ no
matter if they are scalars, arrays or hashes.
Likewise a subroutine returns a single flat list
of values. All the parameters in _at__ are aliases
to the real variable in the calling environment,
meaning if you change _0 etc., it is changed
in the main program. sub mysub my (parm1,
parm2) _at__ call-by-value return parm1
parm2 sub mysub2 return _0 _1
call-by-reference
43
Subroutines 2
There can be any number of return statements in a
subroutine. You can return any number of scalars,
arrays and/or hashes but they will just be
flattened into a list. This means that for
practical purposes, you can return any number of
scalars, but just one array or one hash. The same
argument is valid for parameters passed to the
subroutine. The way around this problem is to use
references. sub passarray my (parm1,
parm2, _at_array) _at__ sub passhash my
(parm1, hash) _at__ Subroutine calls are
usually denoted with my (res1, res2)
calc1(parm1, parm2) my hash calc(1,
_at_parmarray)
44
References
A reference is much like a pointer in other
languages. You create references with the
backslash operator. Examples variablereference
\variable arrayreference
\_at_array hashreference \hash codereference
\subroutine filereference \STDOUT
45
Dereferencing references
You use/dereference the data that your reference
points to in this way. print variablereference
arrayreference0 1 print arrayreference0
_at_tab _at_arrayreference hashreference'alpha
' 1 hash hashreference
codereference('parameter') print
filereference data data ltfilereferencegt I
t is recommended to use the infix operator -gt on
arrays, hashes and subroutines. The examples
below are just different syntactical ways to
express the same thing. hashrefkey
'blabla' hashrefkey 'blabla' hashref-gt
key 'blabla'
46
Is it a reference?
To check if a variable really is a reference use
the ref function to test it. if (ref
hashreference) print "This is a
reference\n" else print "This is a
normal variable\n" If the variable tested is
really a reference, then the type of reference is
returned by ref. if (ref reference eq 'SCALAR')
print "This is a reference to a scalar
(variable)\n" elsif (ref reference eq
'ARRAY') print "This is a reference to an
array\n" elsif (ref reference eq 'HASH')
print "This is a reference to a hash\n" elsif
(ref reference eq 'CODE') print "This is a
reference to a subroutine\n" elsif (ref
reference eq 'REF') print "This is a
reference to another reference\n" There are a
few other possibilities, but they are seldom
used.
47
Subroutines revisited
By passing just the reference to arrays/hashes it
is possible to have any number of lists as
parameters to subroutines just as it is possible
to return references to any number of lists. sub
refarraypass my (arrayref1, arrayref2,
hashref) _at__ print hashref-gtkey if
arrayref11 eq arrayref22 Main
program refarraypass(\_at_monsterarray, \_at_bigarray,
\tinyhash) Passing lists as references is
efficient, both with respect to performance and
memory.
48
Arrays of arrays 1
N-dimensional matrix with arrays of arrays of
arrays. my _at_AoA (1,2,3, 'John', 'Joe,
'Ib', 'Eat', 2) Simple assignment print
AoA12 prints Ib Suppose you want to
read a matrix in from a file while (defined (my
line ltINgt)) my _at_tmp split(' ', line)
push(_at_AoA, _at_tmp) Add anonymous array
(row) to _at_AoA Suppose you want to add a
column to a matrix for (my i 0 i lt AoA
i) push(_at_AoAi, "Some value")
49
Arrays of arrays 2
You could also just assign the values for (my
x 0 x lt 10 x) for (my y 0 y
lt 10 y) AoAxy
somefunction(x, y)
Printing/accessing the AoA for (my x 0 x lt
AoA x) for (my y 0 y lt
AoAx y) print "At Xx, Yy
is ", AoAxy, "\n" A common
mistake print _at_AoA Simply prints a list of
array references
50
Hashes of hashes 1
This is a very flexible (and unordered) data
structure. Simple assignment HoH
('Masterkey1' gt 'Key1' gt 'Value1', 'Key2' gt
'Value2' , 'Masterkey2' gt
'Key1' gt 'Value1', 'KeyX' gt 'ValueY' )
Adding an anonymous hash to the
hash HoH'NewMasterKey' 'NewKey1' gt
'NewValue1', Key2' gt 'Value2' Or if you
have a hash you want to add HoH'NewMasterKey'
MyOldHash Adding a key/value pair in
the "second" level. HoH'MasterKey1''NewKey'
'NewValue'
51
Hashes of hashes 2
Printing/using a single value print
HoH'MasterKey1''Key1' Accessing the
structure foreach my masterkey (keys HoH)
print "First level masterkey\n" foreach my
key (keys HoHmasterkey) print
"key gt HoHmasterkeykey\n"
Beware of the autovivification trap print ups,
trapped unless exists HoHmkeysomekey prin
t right if exists HoHmkey and exists
HoHmkeysomekey
52
Hashes of arrays
Simple assignment HoA ('Numbers' gt 1, 2,
3, 'Names' gt 'John', 'Joe, 'Ib') Adding
an array to the hash my _at_tmp split(' ',
line) HoA'NewKey' _at_tmp Appending a
new element to one the arrays push(_at_HoA'NewKey
', 'SomeValue') Two ways of accessing the
structure print HoA'Numbers'1 prints 2
print HoA'Names'-gt1 prints Joe
53
Arrays of hashes
Simple assignment _at_AoH ('key1' gt 'value1',
'key2' gt 'value2, 'newhashkey1'
gt 'value1', 'key2' gt 'value2,
'anotherhashkey1' gt 'value1', 'key2' gt
'value2) Adding anonymous hash to the
array push(_at_AoH, 'key' gt 'val', 'xkey' gt
'xval') AoH2 'key' gt 'val', 'xkey' gt
'xval' Adding single key/value pair in one of
the hashes AoH1'NewKey' 'NewValue'
Accessing the structure for (my i 0 i lt
AoH i) foreach my key (keys
AoHi) print AoHikey, "\n"

54
Installing modules
  • Perl has a large repository of free modules
    (libraries) available at CPAN.
  • The chosen module has to be installed before use.
  • gunzip and (un)tar
  • run perl Makefile.PL in the created directory
  • make, make test, make install
  • Alternatively use the interactive automated tool
    from commandline
  • perl -MCPAN -e shell
  • Lacking the rights to install modules, you can
    still use most of them by
  • identifying the library file (.pm) and place it
    in the same directory as your
  • program.

55
Module types
Most modules are object oriented where data and
methods are encapsulated in the module. Some
modules are more like a collection of
subroutines. Sometimes you have to decide what to
import in your namespace. Some can be used both
ways. All modules contain an explanation on how
to use them. The magic statement is use module
56
Module old style
An example of a module that simply gives you
access to two functions when you use it is the
CryptSimple module use CryptSimple my data
encrypt(_at_stuff) my _at_same_stuff
decrypt(data) If the module allows you to
import subroutines in your namespace it is
usually done like this use somemodule
qw(function1 function2 function3) Modules like
these are pretty trivial to use, but they are
polluting your namespace.
57
Modules object oriented style
A nice OO module to introduce is CGIMinimal.
The subroutines are available via the object and
are called methods. The object data is not
seen, and is only accessible via the methods.
There is no pollution of your namespace. use
CGIMinimal my cgi CGIMinimal-gtnew
Creating an object instance if (cgi-gttruncated)
Using a method scream_about_bad_form
exit my form_field_value cgi-gtparam('some_f
ield_name')
58
BioPerl example
Transforming sequence files The object is
instantiated a hash with parameters is
used. use BioSeqIO in BioSeqIO-gtnew(-file
gt "inputfilename", -format gt 'Fasta') out
BioSeqIO-gtnew(-file gt "gtoutputfilename",
-format gt 'EMBL') while ( my seq
in-gtnext_seq() ) out-gtwrite_seq(seq)
59
Creating a subroutine collection
Collect your useful subroutines in a file. End
the file with 1 Use the collection by requiring
the file in your program. !/usr/bin/perl
w require mysubcollection.pl This is easy,
but a beginners solution.
60
Creating your own OO module 1
package MyModuleName use strict This
subroutine is automatically called (if it exists)
when the last reference to the object
disappears or the program ends. sub DESTROY
my self shift _at__ close files perhaps
This block is automatically called (if it exists)
when the module is loaded by the main program.
Anything here is executed BEFORE any statements
in the main program. BEGIN
61
Creating your own OO module 2
Instantiating (creating) a new module/class
object. sub new my (self, filename) _at__
my hash self-gt_error("No file name
given") unless filename my filehandle
open(filehandle, filename) or
self-gterror("Can't open file filename\nReason
!") while (defined (my line
ltfilehandlegt)) next unless line
m/gt\S/ Compute on file
hash-gt'_File' filehandle return
bless(hash, ref(self) self)
62
Creating your own OO module 3
Private internal subroutine to handle errors
gracefully. sub _error my (self, msg)
_at__ chomp msg warn "msg\n" exit
Method sub Name my self shift _at__
return self-gt'Name' if self-gt'Name'
return undef
63
Advice 1
Know your problem Very often the reason for
having difficulty in programming is that you do
not know the problem you have not studied the
input enough and seen all the patterns in the
data. You have not analyzed the task sufficiently
and thought about all implications and
consequences. Know your tool Perl is the tool and
when in a learning phase (and we all are) you do
not know what Perl is capable of doing to ease
your task. You must investigate Perl in depth. It
is better for rapid programming to know a small
part very well, instead of just the surface of
most Perl. On the other hand, when faced with a
problem, having surface knowledge of most Perl
enables you to zoom in on features that might
help you.
64
Advice 2
Get started You should not wait until a problem
is completely understood or Perl is completely
learned before programming. Very often deeper
understanding settles as you program, but you
must have the core of understanding first. Your
assumptions trip you up Whenever there is a bug
in the program it is because you have assumed
something about the data or problem, which is not
true, or something about how Perl works, which is
false. Learn to recognize your assumptions and
when found, verify that they are true. Read what
it says, not what you think it says In the same
line as above. Often people do not read the text
properly. Learn to really see the code/input
data/problem description.
Write a Comment
User Comments (0)
About PowerShow.com